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

it print 1 and print 2 but why it happan?

Asked by 3 years ago
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

Log in to vote
1
Answered by 3 years ago

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)
0
thank Trorapantest1 13 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

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)

Answer this question