Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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.

1 comment

0

Thanks a TON!

This discussion is preserved as it was. New answers, comments, and votes are closed.