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

Why isn't my debounce working?

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

✓ Accepted answer

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)

1 comment

0

Thank you, UserOnly16Characters . I should have noticed that.

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