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

How do I debounce this?

Asked by 8 years ago
p = Instance.new("ScreenGui")
a = Instance.new("Frame")
debounce = false
function onTouched(hit)
    if not debounce then
    p.Parent = script.Parent.Parent.Parent.Players.Player.PlayerGui
    a.Parent = p
    a.Size = UDim2.new(2, 0, 2, 0)
    a.Position = UDim2.new(0, 0, -.1, 0)
    a.BackgroundColor3 = Color3.new(0,0,0)
    a.BackgroundTransparency = 1
    wait(.1)
    local man = coroutine.wrap(function()
        for i=1, -0.5, -.05 do
        a.BackgroundTransparency = i
        wait()
        end
        debounce = false
    end)
    man()
    wait(3)
    script.Parent.Parent.Player.Torso.CFrame = CFrame.new(Vector3.new(0, 0, 0))
    end
end

script.Parent.Touched:connect(onTouched)

I don't understand the wiki entry, can someone help?

1 answer

Log in to vote
0
Answered by 8 years ago

Debounces
Like rubber balls.

You need to set debounce to true at the start of the function, and set it to false at the end.

p = Instance.new("ScreenGui")
a = Instance.new("Frame")
debounce = false
function onTouched(hit)
    if not debounce then
    debounce = true; -- Here
    p.Parent = script.Parent.Parent.Parent.Players.Player.PlayerGui
    a.Parent = p
    a.Size = UDim2.new(2, 0, 2, 0)
    a.Position = UDim2.new(0, 0, -.1, 0)
    a.BackgroundColor3 = Color3.new(0,0,0)
    a.BackgroundTransparency = 1
    wait(.1)
    local man = coroutine.wrap(function()
        for i=1, 0.5, -.05 do -- FTFY
        a.BackgroundTransparency = i
        wait()
        end
        a.BackgroundTransparency = 0.5
        debounce = false -- And there.
    end)
    man()
    wait(3)
    script.Parent.Parent.Player.Torso.CFrame = CFrame.new(Vector3.new(0, 0, 0))
    end
end

script.Parent.Touched:connect(onTouched)
0
Wow man, thanks! spacegang 16 — 8y
Ad

Answer this question