I'm wondering how I can have a part that only registers getting touched once and ends the code instead of having it repeatedly run the code every time it gets touched like I have below:
local health = script.Parent.Parent.Health.Value function onHit(hit) health = health - 10 print (health) end script.Parent.Touched:connect(onHit)
You could use something like debounce, or make a table of players who already have touched the ting.
Debounce:
local health = script.Parent.Parent.Health.Value local Debounce = false script.Parent.Touched:connect(onHit) if Debounce == false then Debounce = true health = health - 10 print (health) wait(INSERT TIME UNTIL YOU CAN TOUCH THE PART AGAIN) Debounce = false end
local health = script.Parent.Parent.Health.Value
function onHit(hit)
health = health - 10
print (health)
end
script.Parent.Parent.Touched:connect(onHit)
script.Parent.Parent.Touched:connect(onHit)
wait(5)