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

My script won't work after I added if debounce == false?

Here's my script. It works fine until I added if debounce == false then A working script or tell me how to fix this?

local player = game.Players.LocalPlayer
local weapons = script.Parent.Parent:WaitForChild("weapons"):GetChildren()
local spinTime = 1
local numberOfSpins = 1

local debounce = false

script.Parent.MouseButton1Click:connect(function()
	if debounce == false then
	if player.leaderstats.BUX.Value >= 300 then
	player.leaderstats.BUX.Value = player.leaderstats.BUX.Value - 300
		script.Parent.Parent.State.Text = "Spinning..."
		script.Parent.Parent.State.Visible = true
		print("Starting")
		debounce = true
		local finalWeapon = weapons[math.random(1, #weapons)]
	
		for i = 1, numberOfSpins do
			if i == numberOfSpins then
				for _,v in pairs(weapons) do
					v.Visible = false
				end
				finalWeapon.Visible = true
				print("Finished")
				script.Parent.Parent.State.Text = "You got: " .. finalWeapon.Name
				break
			end
			local thisWeapon = weapons[math.random(1, #weapons)]
			thisWeapon.Visible = true
			wait(spinTime / numberOfSpins)
			thisWeapon.Visible = false
		end
	end
	debounce = false
	end
end)

1 answer

✓ Accepted answer
local player = game.Players.LocalPlayer
local weapons = script.Parent.Parent:WaitForChild("weapons"):GetChildren()
local spinTime = 1
local numberOfSpins = 1

local debounce = false

script.Parent.MouseButton1Click:connect(function()
    if debounce == false then
    debounce = true
    if player.leaderstats.BUX.Value >= 300 then
    player.leaderstats.BUX.Value = player.leaderstats.BUX.Value - 300
        script.Parent.Parent.State.Text = "Spinning..."
        script.Parent.Parent.State.Visible = true
        print("Starting")
        debounce = true
        local finalWeapon = weapons[math.random(1, #weapons)]

        for i = 1, numberOfSpins do
            if i == numberOfSpins then
                for _,v in pairs(weapons) do
                    v.Visible = false
                end
                finalWeapon.Visible = true
                print("Finished")
                script.Parent.Parent.State.Text = "You got: " .. finalWeapon.Name
                break
            end
            local thisWeapon = weapons[math.random(1, #weapons)]
            thisWeapon.Visible = true
            wait(spinTime / numberOfSpins)
            thisWeapon.Visible = false
        end
    end
    debounce = false
    end
end)

You need to first change debounce to true and after everything is done turn it back to false. I added debounce = true after the first if statement.

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