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

What do I put for what's being touched? [Answered]

Asked by 10 years ago

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!

2 answers

Log in to vote
3
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
10 years ago

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)
Ad
Log in to vote
2
Answered by 10 years ago
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)

0
can anyone elaborate why is has to be hit? I dont understand why MrN00bReaper 30 — 10y
0
why it* MrN00bReaper 30 — 10y

Answer this question