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

Leaderstats GUI Button Script For StarterGUI Not Working?

So, i'm making a simulator where you click a gui button, and it raises your leaderstat. (The leaderstat is called Snow) I have a script, but it won't work. Anyone know why? Thank you.

debounce = false

function onClick(Player)
	if not debounce then
		debounce = true
			for _,Player in pairs(game.Players:GetPlayers()) do
			if Player:findFirstChild("leaderstats") then
			Player.leaderstats.Snow.Value = Player.leaderstats.Snow.Value +1
			wait(0.1)
			debounce = false
			
			end
		end
	end
end

script.Parent.ClickDetector.MouseClick:connect(onClick)

1 answer

✓ Accepted answer

It may have something to do with the debounce. It is in the if statement, so it might not change to false

debounce = false

function onClick(Player)
	if not debounce then
		debounce = true
		for _,Player in pairs(game.Players:GetPlayers()) do
			if Player:FindFirstChild("leaderstats") then
				Player.leaderstats.Snow.Value = Player.leaderstats.Snow.Value +1
				wait(0.1)
			end
		end
		debounce = false
	end
end

script.Parent.ClickDetector.MouseClick:Connect(onClick)

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