| Touched event | |
|
|
|
Author | Message |
---|
Guest Guest
| Subject: Touched event August 2nd 2010, 3:04 pm | |
| Please move this if its in the wrong level. Introduction/What it isonTouch functions are activated when a person touches a brick the script is in. They are used in lava bricks, VIP doors, and more. In this tutorial you will find out how to create an onTouch function and run it when someone touches the brick. Setting upFirst, insert a Part (aka brick). If you don't know how to do this, read a different tutorial first. Now, insert a script inside the brick. Double-click your script and it should open up. You will see: - Code:
-
print("Hello World!") Delete that line. You don't need it. Making the scriptFirst, we need to define our function. - Code:
-
function onTouch() After creating our function, we need it to do something when activated. How about we use a simple action and remove our brick? - Code:
-
script.Parent:remove() That refers to the parent of the script (in this case, our brick) and then removes it. Finish the function with an end . Now we're almost done! We need our script to activate when touched, so we'll use this connection line. - Code:
-
script.Parent.Touched:connect(onTouch) The final scriptOur completed script looks like this... - Code:
-
function onTouch() script.Parent:remove() end
script.Parent.Touched:connect(onTouch) Now go test your script. Does your brick disappear when you touch it? Does this help? Is there something incorrect within it? Tell me and I'll try to fix it.
Last edited by Nominate10 on August 2nd 2010, 5:22 pm; edited 1 time in total (Reason for editing : Title changed.) |
|
| |
slayer9365 Expert Scripter
Posts : 233 Join date : 2010-07-31 Age : 29
| Subject: Re: Touched event August 2nd 2010, 4:55 pm | |
| I wouldn't call it onTouch functions, because you could have the function named everything. I could have function poop(iTouchedYou). Please change the *** to the .Touched event. | |
|
| |
Guest Guest
| Subject: Re: Touched event August 2nd 2010, 5:21 pm | |
| Yes, but most beginners refer to it as an onTouch function. Good call though, I'll change that. |
|
| |
slayer9365 Expert Scripter
Posts : 233 Join date : 2010-07-31 Age : 29
| Subject: Re: Touched event August 2nd 2010, 5:23 pm | |
| Well beginers need to learn some how that Names of functions don't really matter.
Last edited by slayer9365 on August 2nd 2010, 5:24 pm; edited 1 time in total (Reason for editing : My keyboard cut out halfway through my sentence) | |
|
| |
Guest Guest
| Subject: Re: Touched event January 16th 2011, 10:41 pm | |
| Well what if another brick touches it, not including a player? |
|
| |
naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: Touched event January 16th 2011, 10:51 pm | |
| | |
|
| |
Guest Guest
| Subject: Re: Touched event January 16th 2011, 11:30 pm | |
| So I think you should recreate you script, Nominate10. |
|
| |
naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: Touched event January 16th 2011, 11:58 pm | |
| His script was meant to be the most basic form of the Touched event. To make it only activate by players, this will work: - Code:
-
function onTouch(hit) if hit:findFirstChild("Humanoid") then script.Parent:Remove() end end
script.Parent.Touched:connect(onTouch)
| |
|
| |
blueymaddog Administrator
Posts : 1081 Join date : 2010-12-09 Age : 26
| Subject: Re: Touched event January 17th 2011, 3:56 am | |
| | |
|
| |
naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: Touched event January 17th 2011, 12:38 pm | |
| | |
|
| |
blueymaddog Administrator
Posts : 1081 Join date : 2010-12-09 Age : 26
| Subject: Re: Touched event January 18th 2011, 8:06 am | |
| not always. these errors you made for example: m=Instance.new("Message",Workspace).Text="" pcall(hit.Parent.Humanoid.Health=0 end) | |
|
| |
Guest Guest
| Subject: Re: Touched event January 23rd 2011, 4:20 pm | |
| - naknak wrote:
- His script was meant to be the most basic form of the Touched event. To make it only activate by players, this will work:
- Code:
-
function onTouch(hit) if hit:findFirstChild("Humanoid") then script.Parent:Remove() end end
script.Parent.Touched:connect(onTouch)
Incorrect. The Character of players has the Humanoid stored in the model, not one of the Parts in the model. - Code:
-
function Potatoes(wut) if wut.Parent:findFirstChild("Humanoid") then script.Parent:Remove() end end
script.Parent.Touched:connect(Potatoes)
|
|
| |
slayer9365 Expert Scripter
Posts : 233 Join date : 2010-07-31 Age : 29
| Subject: Re: Touched event January 23rd 2011, 4:41 pm | |
| Very nice job catching that Potato. | |
|
| |
Guest Guest
| Subject: Re: Touched event January 23rd 2011, 5:19 pm | |
| |
|
| |
naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: Touched event January 23rd 2011, 5:57 pm | |
| Fine. Give me a break, everyone makes mistakes. I know what I mean, even if I say it wrong... And how were those mistakes blue? | |
|
| |
Supernapalm Expert Scripter
Posts : 393 Join date : 2011-01-17
| Subject: Re: Touched event January 23rd 2011, 7:33 pm | |
| ikr. i was just thinking about that touch script. | |
|
| |
myrco919 Intermediate Scripter
Posts : 190 Join date : 2011-01-21 Age : 26 Location : Holland
| Subject: Re: Touched event January 24th 2011, 10:01 am | |
| | |
|
| |
blueymaddog Administrator
Posts : 1081 Join date : 2010-12-09 Age : 26
| Subject: Re: Touched event January 26th 2011, 10:02 am | |
| *finds another catch!!!* @potato, what if a talking brick touched it? ever thought of that? use this: - Code:
-
script.Parent.Touched:connect(function(hit) if game.Players:GetPlayerFromCharacter(hit.Parent) ~= nil then hit:Remove() end end)
| |
|
| |
slayer9365 Expert Scripter
Posts : 233 Join date : 2010-07-31 Age : 29
| Subject: Re: Touched event January 26th 2011, 5:34 pm | |
| - blueymaddog wrote:
- *finds another catch!!!*
@potato, what if a talking brick touched it? ever thought of that?
I am not sure what a talking brick is, I don't think that bricks are AI yet. And if you are talking about a model with a humanoid in it, I think that most people will either rename the Humanoid, or have them anchored. | |
|
| |
blueymaddog Administrator
Posts : 1081 Join date : 2010-12-09 Age : 26
| Subject: Re: Touched event January 26th 2011, 10:22 pm | |
| but what if it isn't anchored and humanoid isn't renamed? lol :P | |
|
| |
naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: Touched event January 26th 2011, 10:38 pm | |
| Then whoever made the talking brick needs help. | |
|
| |
blueymaddog Administrator
Posts : 1081 Join date : 2010-12-09 Age : 26
| Subject: Re: Touched event January 27th 2011, 2:27 am | |
| | |
|
| |
ninga95 Administrator
Posts : 122 Join date : 2010-07-30 Age : 29
| Subject: Re: Touched event February 10th 2011, 9:30 pm | |
| Hey if nom looks at this i think he would be like WOW i wrote this when i first started lol Hes like an expert now | |
|
| |
myrco919 Intermediate Scripter
Posts : 190 Join date : 2011-01-21 Age : 26 Location : Holland
| Subject: Re: Touched event March 5th 2011, 6:38 pm | |
| | |
|
| |
naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: Touched event March 5th 2011, 8:59 pm | |
| Yeah, this is a pretty basic guide. | |
|
| |
Sponsored content
| Subject: Re: Touched event | |
| |
|
| |
| Touched event | |
|