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

why won't local debounce = false work?

Asked by 6 years ago

I don't know why, but the debounce on this script wont work. I'm not very good with debounce, so i don't know what's failing. Even though I have the debounce script, this script will play a million times when touched

--Variables
function fade()
    script.Parent.Parent.Enabled = true
    for i = 0, 1, 0.05 do
        script.Parent.TextTransparency = i
        wait(0.05)
    end
    for i = 1, 0, -0.05 do
        script.Parent.TextTransparency = i
        print(i)
        wait(0.05)
    end
    script.Parent.Parent.Enabled = false
    return
end

local debounce = false
--Variables

workspace.Earth.Earth.Touched:connect(function()
    if debounce == false then
        debounce = true
        -- script.Parent.Text = "Earth"
        fade()
    end
end)

workspace.Earth.Earth.TouchEnded:connect(function()
    if debounce == true then
        debounce = false
        script.Parent.Parent.Enabled = false
        wait(1)
        debounce = false
    end
end)

I don't know what's wrong.

0
I don't see the point of the debounce though :/ greatneil80 2647 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

A player touches a part infinite times in a second, that being said, if you have the same part connected to two touched function then the debounce is completely useless, the value will change and the other function will run, instead of using the same part, use two different parts in the same script and it should work perfectly.

Ad

Answer this question