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

How can I send a parameter through activating an event?

Asked by 4 years ago
function onMouseClick(flame)
    if cooldown then
        cooldown = false
        if flame == 1 then
            onOrOff(sp.flame1.Flame,sp.flame1.Sparks)
        elseif flame == 2 then
            onOrOff(sp.flame2.Flame,sp.flame2.Sparks)
        elseif flame == 3 then
            onOrOff(sp.flame3.Flame,sp.flame3.Sparks)
        elseif flame == 4 then
            onOrOff(sp.flame4.Flame,sp.flame4.Sparks)
        elseif flame == 5 then
            onOrOff(sp.flame5.Flame,sp.flame5.Sparks)
        end
        wait(1)
        cooldown = true
    end
end

clickDetector1.MouseClick:connect(onMouseClick(1))
clickDetector2.MouseClick:connect(onMouseClick(2))
clickDetector3.MouseClick:connect(onMouseClick(3))
clickDetector4.MouseClick:connect(onMouseClick(4))
clickDetector5.MouseClick:connect(onMouseClick(5))

What i want to do is use a parameter for onMouseClick(5) so they all go to one function, but that does't seem possible. What's the best way for me to do this?

1 answer

Log in to vote
0
Answered by
TrippyV 314 Donator Moderation Voter
4 years ago
Edited 4 years ago

You'd likely have to create an anonymous function during the connection and call your OnMouseClick function from there, like so:

(replace this code with what you have on lines 20-24)

clickDetector1.MouseClick:Connect(function()
    onMouseClick(1)
end)

clickDetector2.MouseClick:Connect(function()
    onMouseClick(2)
end)

clickDetector3.MouseClick:Connect(function()
    onMouseClick(3)
end)

clickDetector4.MouseClick:Connect(function()
    onMouseClick(4)
end)

clickDetector5.MouseClick:Connect(function()
    onMouseClick(5)
end)

If you have any more questions, be sure to comment and I'll help you out :)

Ad

Answer this question