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

Why is this function running 16 times even with debounce?

I've got debounce and this function's running 16 times each time

game.Players.PlayerAdded:Connect(function(player)
local MoneyBoard = Instance.new("Folder")
MoneyBoard.Name = "leaderstats"
	local Money = Instance.new("IntValue", MoneyBoard)
	Money.Name = "Money"
Money.Value = 0
	MoneyBoard.Parent = player
	local db = false
	
	game.Workspace.MoneyCollector.Touched:Connect(function(hit)
		if not db then
			local db = true
		if hit.Parent:FindFirstChild("HumanoidRootPart") then
			game.Players:GetPlayerFromCharacter(hit.Parent)
			if db == true then
				print(5)
			end
			if player then
				while Money.Value <30000000 do
					Money.Value = Money.Value + 1000
						wait(2)
						end
				end
			end
		end
	end)
end)
local db = false

1 answer

✓ Accepted answer

Remove local from line 12

db = true

Local causes the variable to be changed only within the if statement.

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