Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-2

Events and Connections like so; function onTouched(hit)?

Asked by
KAAK82 16
10 years ago

I would like to know the Connections, cos Touched is Hit.Parent, and so I wanna know more, maybe Button1Down would have the Tool? So Anyway, plz help me here guys!

2 answers

Log in to vote
8
Answered by 10 years ago

I didn't understand connections for a long time but what I've learned is look in the object explorer and select of thing you're modifying. Part, mouse, tool, etc. On the right of your screen should have all the things you can use with that object. Under part for example there would be Touched. So for a touching a part it would be:

function onTouch(hit)
    --hit its the part that touches it
    --code here
end

script.Parent.Touched:connect(hit) --script.Parent would be the part that is being touched. You could do like game.Workspace.bob.Touched:connect(hit) if wanted
-- the (hit) after :connect is the function its 'completing'.

An 'advanced' function is what I call a function that has the connect in the function line, EX:

script.Parent.Touched:connect(function(hit)
    -- code
end) -- the end has an ) after it because its completing parentheses, as you can see in line 1 the parentheses are not completed so you need that parentheses. 

This type of 'advanced' function helps save time because you don't have to scroll down to the end of the script to check if you called the connect or 'completed' the function yet.

For gui textbuttons or imagebuttons if you want it to do something when its clicked you would do a function like this:

script.Parent.MouseButton1Click(function(click)
    script.Parent.Text = "IT CHANGED ZOMG"
end)

You don't need that line on the bottom connecting the Function (click) to mousebutton1click because you used an 'advanced' function.

This took a good 15 minutes of writing. Hope it helped, I really had issues with this stuff before so I hope I can make it easier for you :)

0
It's technically called an anonymous function but you can call it whatever you want lol Ekkoh 635 — 10y
Ad
Log in to vote
0
Answered by
MrNicNac 855 Moderation Voter
10 years ago

Here is a document of all the events.

All Events

0
thnx, but I already know this link... I just cant get wat all the Events do in the '()' cos hit.Parent then (key) so am doing research now KAAK82 16 — 10y
0
Yeah, I just had no idea - whatsoever - your question was. I'm not sure how anyone could... MrNicNac 855 — 10y

Answer this question