script.Parent.Touched:connect(function(part) -- make sure the part still exists if not part.Parent then return end -- make sure it's a humanoid local humanoid = part.Parent:FindFirstChild("Humanoid") if not humanoid then return end workspace.nocpp.Value = workspace.nocpp.Value - 1 end)
How do i prevent workspace.nocpp.value from negating if the part(the parent of the script) was touched by the same person twice or more?
Thepoint13's answer will suffice, however you can also do it within the same script.
last = {} -- Last Player to touch local debounce = false -- Debounce to prevent multiple touches at the same time. script.Parent.Touched:connect(function(part) if debounce == false then -- make sure the part still exists if not part.Parent then return end -- make sure it's a humanoid local humanoid = part.Parent:FindFirstChild("Humanoid") if not humanoid then return end debounce = true if part.Parent.Name ~= last then -- If Player wasn't the last player to touch then last = part.Parent.Name print(last, "Touched") wait(.5) debounce = false else -- If the player was the last person to touch then print("Player already touched") debounce = false end end end)
One problem with this script however, is the player won't be able to touch the brick again until another player does. You could add a StringValue somewhere and make last = StringValue, then have a separate script reset the last touched every so often.
You can either put a local script inside the player with a variable, when the player touches, you change the value inside it. Use Fireserver() to do this.
You can also use tables. Use table.Import the players name.