I have this script that is suposed to increase a value by one if a player touches the part it and decrease it by one if that same player touches the part again but sometimes it activates more than once per touch rapidly adding and substracting numbers:
local b =false script.Parent.Touched:connect(function(move) if b == false and move.Parent:FindFirstChild("Torso") then b = true if not move.Parent.Torso:FindFirstChild("num") then local c = Instance.new("BoolValue") c.Name = "num" c.Value = true c.Parent = move.Parent.Torso script.Parent.Value.Value = script.Parent.Value.Value + 1 wait() elseif move.Parent.Torso:FindFirstChild("num") and move.Parent.Torso.num.Value == true then move.Parent.Torso.num.Value = false script.Parent.Value.Value = script.Parent.Value.Value - 1 wait() elseif move.Parent.Torso:FindFirstChild("num") and move.Parent.Torso.num.Value == false then move.Parent.Torso.num.Value = true script.Parent.Value.Value = script.Parent.Value.Value + 1 wait() end wait() end wait() b = false end)
The debounce value is outside the first if statement, so it is set to false every time the part is touched.
local b = false script.Parent.Touched:connect(function(move) if b == false and move.Parent:FindFirstChild("Torso") then b = true if not move.Parent.Torso:FindFirstChild("num") then local c = Instance.new("BoolValue") c.Name = "num" c.Value = true c.Parent = move.Parent.Torso script.Parent.Value.Value = script.Parent.Value.Value + 1 elseif move.Parent.Torso:FindFirstChild("num") and move.Parent.Torso.num.Value == true then move.Parent.Torso.num.Value = false script.Parent.Value.Value = script.Parent.Value.Value - 1 elseif move.Parent.Torso:FindFirstChild("num") and move.Parent.Torso.num.Value == false then move.Parent.Torso.num.Value = true script.Parent.Value.Value = script.Parent.Value.Value + 1 end wait(1) --single wait b = false end end)
I am pretty sure the reason for that is because your wait time is way too little... Also for a cool down I suggest using a Debounce
it's simple and it's more efficient Or so I think so....