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

it print 1 and print 2 but why it happan?

local Button = script.Parent.Button
local Green = script.Parent.Green
local Red = script.Parent.Red
local LightHolo = script.Parent.Light
local ClickDetector = script.Parent.Button:WaitForChild("ClickDetector")
local debouce = true

function off()
	if debouce == false then
		Button.CFrame = Button.CFrame * CFrame.new(0.063,0,0)
		print("2")
		debouce = true
	end
end

function on()
	if debouce == true then
		Button.CFrame = Button.CFrame * CFrame.new(-0.063,0,0)
		print("1")
		debouce = false
	end
end

ClickDetector.MouseClick:Connect(function()
	if debouce == true then
		on()
	end
	if debouce == false then
		off()
	end
end)

2 answers

✓ Accepted answer

i think its cos when debounce is true, it makes it false so when it moves to the next line it will show as false and change to true again.

try adding a return after like this i gues

ClickDetector.MouseClick:Connect(function()
    if debouce == true then
        on()
	return
    end
    if debouce == false then
        off()
    end
end)

1 comment

0

thank

This should work!

local Button = script.Parent.Button
local Green = script.Parent.Green
local Red = script.Parent.Red
local LightHolo = script.Parent.Light
local ClickDetector = script.Parent.Button:WaitForChild("ClickDetector")
local debouce = true

function off()
        Button.CFrame = Button.CFrame * CFrame.new(0.063,0,0)
        print("off")
        debouce = true
end

function on()
        Button.CFrame = Button.CFrame * CFrame.new(-0.063,0,0)
        print("on")
        debouce = false
end

ClickDetector.MouseClick:Connect(function()
    if debouce == true then
        on()
   else
        off()
    end
end)

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