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

How do you detect when a player clicks a button twice to trigger two different functions?

Asked by
Spooce 78
10 years ago

The lights turn off right when the first parts ends, I understand that. But how do you detect when a player clicks the same button to trigger two different functions?

local Button = script.Parent
local Click = script.Parent.Click
local State = script.Parent.State

function onClick()
    Button.CFrame = CFrame.new(Button.Position - Vector3.new(0, 0.2, 0))
    wait(0.01)
    Button.CFrame = CFrame.new(Button.Position + Vector3.new(0, 0.2, 0))
    Click:Play()
    if State.Value == 0 then
        wait(1)
        script.Parent.Parent.One.Light.PointLight.Enabled = true
        script.Parent.Parent.Two.Light.PointLight.Enabled = true
        wait(1)
        script.Parent.Parent.Three.Light.PointLight.Enabled = true
        script.Parent.Parent.Four.Light.PointLight.Enabled = true
        wait(1)
        script.Parent.Parent.Five.Light.PointLight.Enabled = true
        script.Parent.Parent.Six.Light.PointLight.Enabled = true
        wait(1)
        script.Parent.Parent.Seven.Light.PointLight.Enabled = true
        script.Parent.Parent.Eight.Light.PointLight.Enabled = true
        State.Value = 1
    end
        if State.Value == 1 then
            script.Parent.Parent.One.Light.PointLight.Enabled = false
            script.Parent.Parent.Two.Light.PointLight.Enabled = false
            wait(1)
            script.Parent.Parent.Three.Light.PointLight.Enabled = false
            script.Parent.Parent.Four.Light.PointLight.Enabled = false
            wait(1)
            script.Parent.Parent.Five.Light.PointLight.Enabled = false
            script.Parent.Parent.Six.Light.PointLight.Enabled = false
            wait(1)
            script.Parent.Parent.Seven.Light.PointLight.Enabled = false
            script.Parent.Parent.Eight.Light.PointLight.Enabled = false
            State.Value = 0
        end
end

Button.ClickDetector.MouseClick:connect(onClick)

1 answer

Log in to vote
0
Answered by 10 years ago

i think you should do like this:

local Button = script.Parent
local Click = script.Parent.Click
local State = script.Parent.State

function onClick()
    Button.CFrame = CFrame.new(Button.Position - Vector3.new(0, 0.2, 0))
    wait(0.01)
    Button.CFrame = CFrame.new(Button.Position + Vector3.new(0, 0.2, 0))
    Click:Play()
    if State.Value == 0 then
        wait(1)
        script.Parent.Parent.One.Light.PointLight.Enabled = true
        script.Parent.Parent.Two.Light.PointLight.Enabled = true
        wait(1)
        script.Parent.Parent.Three.Light.PointLight.Enabled = true
        script.Parent.Parent.Four.Light.PointLight.Enabled = true
        wait(1)
        script.Parent.Parent.Five.Light.PointLight.Enabled = true
        script.Parent.Parent.Six.Light.PointLight.Enabled = true
        wait(1)
        script.Parent.Parent.Seven.Light.PointLight.Enabled = true
        script.Parent.Parent.Eight.Light.PointLight.Enabled = true
        State.Value = 1
    else if State.Value == 1 then
        script.Parent.Parent.One.Light.PointLight.Enabled = false
        script.Parent.Parent.Two.Light.PointLight.Enabled = false
        wait(1)
        script.Parent.Parent.Three.Light.PointLight.Enabled = false
        script.Parent.Parent.Four.Light.PointLight.Enabled = false
        wait(1)
        script.Parent.Parent.Five.Light.PointLight.Enabled = false
        script.Parent.Parent.Six.Light.PointLight.Enabled = false
        wait(1)
        script.Parent.Parent.Seven.Light.PointLight.Enabled = false
        script.Parent.Parent.Eight.Light.PointLight.Enabled = false
        State.Value = 0
    end
    end
end

Button.ClickDetector.MouseClick:connect(onClick)

hope it helps.

0
Thanks a TON! Spooce 78 — 10y
Ad

Answer this question