I want to make it so that when you touch a certain part, it changes color and you get one point.
However it adds more than one point.
How do i fix this?
if player.Team == Teams["Red"] then
local debounce = false
script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and not debounce then
debounce = true
script.Parent.BrickColor = BrickColor.new("Really red")
player.leaderstats.Square.Value = player.leaderstats.Square.Value + 1
debounce = false
end
end)
As soon as you earn +1 squares, debounce is set back to false which is the problem. You would want to set it to false after some time:
local coolDown = -- coolDown in numbers
if player.Team == Teams["Red"] then
local debounce = false
script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and not debounce then
debounce = true
script.Parent.BrickColor = BrickColor.new("Really red")
player.leaderstats.Square.Value = player.leaderstats.Square.Value + 1
wait(coolDown)
debounce = false
end
end)
Then you can just set debounce to true and never set it back to false when a player earns a square:
if player.Team == Teams["Red"] then
local debounce = false
script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and not debounce then
debounce = true
script.Parent.BrickColor = BrickColor.new("Really red")
player.leaderstats.Square.Value = player.leaderstats.Square.Value + 1
end
end)