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

How do you substitute a parameter within an event (Touched Event)?

Asked by 6 years ago
Edited 6 years ago

So I have a function that will fire whenever a part touch something and I want some parameters in it, and how do I do that?

Here's the original script:

function explode(hit, parameter)
    print(parameter) -- result is nil
end

script.Parent.Touched:connect(explode)

So how do I give value to that parameter? Do I put a value after the comma like this?

function explode(hit, parameter)
    print(parameter) -- result is still nil
end

script.Parent.Touched:connect(explode, "BOOM")

And also, another question, If I don't use functions and make a touch event like this:

script.Parent.Touched:connect(function(hit, parameter)
    print(hit) -- obviously, the part that touched it
    print(parameter) -- if I test it now, it will just be nil
end)

So the "hit" is the part that touched it, and for the "parameter", how do you even add value to it?

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

You can do something like this to provide your own parameters along with the given ones:

function onTouched(hit,parameter)
    print(hit)
    print(parameter)
end

script.Parent.Touched:Connect(function(hit)
    local parameter = "BOOM"
    onTouched(hit,parameter)
end)

See this last example in Usage for 'changing' arguments.

Ad

Answer this question