I have already tried to use a debounce for this but it has not worked for me. I need help so that when a playe rtouches an object, the function only goes off once. Heres my code.
local balance = 0
local part = script.Parent
local debounce = false
part.Touched:Connect(function(hit)
if debounce == false then
debounce = true
balance += 1
part.CanCollide = false
debounce = false
end
end)
Remove the denounce = false part near the bottom to fix that, you’re basically just calling the function, checking if denounce is off, turning it on, and then back off so it’ll just run forever.
local balance = 0
local part = script.Parent
local debounce = false
part.Touched:Connect(function(hit)
if debounce == false then
debounce = true
balance += 1
part.CanCollide = false
wait(1)
debounce = false
end
end)
Thank you so much and this helped a ton but I am respawning the part randomly in a test version very similar to this and it is not allowing me to hit it again.
Oh i see what you mean, you think the OP only wants the entire function to run once and never run again? but why did he even mention debounce then? Hmmm, lets see how they respond.
But they also said this:
Which makes me believe they want a debounce to work.