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

Why isn't my debounce working?

Asked by
AZDev 590 Moderation Voter
9 years ago

Here is my code, it worked while there was only one if statement.

local debounce = false



script.Parent.Button.ClickDetector.MouseClick:connect(function(onClick)
    if debounce == false then
        debounce = true
    end

    if workspace.ButtonBooleans.isBought.Value == false then
        local part = Instance.new("Part")
        part.Position = script.Parent.PrimaryPart.Position
        part.Size = Vector3.new(1, 1, 1)
        part.Material = Enum.Material.CorrodedMetal --material code = 1040
        part.Name = "RustMetal"
        part.Parent = script.Parent
        part.Color = Color3.new("Dark stone grey")
        wait(0.5)
        debounce = false

        wait(6)
        local Player = game.Players.LocalPlayer
        Player:WaitForChild("leaderstats").Money.Value = Player:WaitForChild("leaderstats").Money.Value + 1


        else if workspace.ButtonBooleans.isBought.Value == true then



            script.Parent:WaitForChild("Duplicator")
            local part = Instance.new("Part")
            part.Position = script.Parent.PrimaryPart.Position
            part.Size = Vector3.new(1, 1, 1)
            part.Material = Enum.Material.CorrodedMetal --material code = 1040
            part.Name = "RustMetal"
            part.Parent = script.Parent
            part.Color = Color3.new("Dark stone grey")

            local Dpart = Instance.new("Part")
            Dpart.Parent = script.Parent
            Dpart.Position = script.Parent.Duplicator.PrimaryPart.Position
            Dpart.Size = Vector3.new(1, 1, 1)
            Dpart.Material = Enum.Material.CorrodedMetal -- material code = 1040
            Dpart.Name = "RustMetal"
            Dpart.Color = Color3.new("Dark stone grey")
            wait(0.5)
            debounce = false

            wait(6)
            local Player = game.Players.LocalPlayer
            Player:WaitForChild("leaderstats").Money.Value = Player:WaitForChild("leaderstats").Money.Value + 2
        end
    end
end)

1 answer

Log in to vote
1
Answered by 9 years ago

The problem was when you made you Debounce if statement you added a end right after it which meant the Debounce basically stoped right after you created the if statement this caused it to not take effect.

local debounce = false



script.Parent.Button.ClickDetector.MouseClick:connect(function(onClick)
    if debounce == false then
        debounce = true

    if workspace.ButtonBooleans.isBought.Value == false then
        local part = Instance.new("Part")
        part.Position = script.Parent.PrimaryPart.Position
        part.Size = Vector3.new(1, 1, 1)
        part.Material = Enum.Material.CorrodedMetal --material code = 1040
        part.Name = "RustMetal"
        part.Parent = script.Parent
        part.Color = Color3.new("Dark stone grey")
        wait(0.5)
        debounce = false

        wait(6)
        local Player = game.Players.LocalPlayer
        Player:WaitForChild("leaderstats").Money.Value = Player:WaitForChild("leaderstats").Money.Value + 1


        else if workspace.ButtonBooleans.isBought.Value == true then



            script.Parent:WaitForChild("Duplicator")
            local part = Instance.new("Part")
            part.Position = script.Parent.PrimaryPart.Position
            part.Size = Vector3.new(1, 1, 1)
            part.Material = Enum.Material.CorrodedMetal --material code = 1040
            part.Name = "RustMetal"
            part.Parent = script.Parent
            part.Color = Color3.new("Dark stone grey")

            local Dpart = Instance.new("Part")
            Dpart.Parent = script.Parent
            Dpart.Position = script.Parent.Duplicator.PrimaryPart.Position
            Dpart.Size = Vector3.new(1, 1, 1)
            Dpart.Material = Enum.Material.CorrodedMetal -- material code = 1040
            Dpart.Name = "RustMetal"
            Dpart.Color = Color3.new("Dark stone grey")
            wait(0.5)
            debounce = false

            wait(6)
            local Player = game.Players.LocalPlayer
            Player:WaitForChild("leaderstats").Money.Value = Player:WaitForChild("leaderstats").Money.Value + 2
            end--Here is where you if statement end should of been.
        end
        end
end)

0
Thank you, UserOnly16Characters . I should have noticed that. AZDev 590 — 9y
Ad

Answer this question