Ok so I posted something related to this earlier, I am making a move that reflect projectiles that use BodyVelocity so I thought I would use a .touch function and when it comes into this move it would reverse the velocity which hopefully would reflect it. I am pretty new to scripting so I have a script within a tool that generates the move (a wall pretty much) but when I created a seperate script for the reflection part I didn't know what to put for whats being touched and I still don't. Would I just put the tool, if I need to post the script please say so in the comments thanks!
In response to your comments on Fidgeting's answer: it doesn't.
The only important bit of the code there is the connection line:
script.Parent.Touched:connect(Ontouched)
Ontouched
is the variable that contains the function you want to have called when the Touched
event of script.Parent
is fired.
To put that in other words, you could rewrite that as this:
script.Parent.Touched:connect(function(hit) end)
And the code will execute identically. (The actual bytecode is different, but that's beyond the scope of this answer.)
Anyway, the hit
parameter there is passed an argument by the Touched
Event firing: the part that 'hit' script.Parent
. Calling it 'hit' is just a way for scripters to remember what it means. You can call that parameter anything you think fits.
script.Parent.Touched:connect(function(blorp) print(blorp.Name) end)
The above is perfectly valid code, identical to:
script.Parent.Touched:connect(function(hit) print(hit.Name) end)
function Ontouched(hit) -- add your script here end script.Parent.Touched:connect(Ontouched)
Add you script where the double hyphens are. (Doubles hyphens are used to make comments around your script, so it wouldn't break it)