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)

2 comments
is there a way to make it work without adding wait(1)? it seems like it can't produce problems if two players touch the part almost at the same time
Maybe. Is the problem that the value will increase/decrease two times in a row? If so this is because the bool values in the characters are different. You could make it so that touching the part toggles a single bool value instead individual ones per character, but in your question you say " if that same player touches the part again". Does this mean unique values for each character?