Making a script that when someone hits an object a certain amount of times (5 right now) the object's CanCollide will turn false.
numOfHits = 0
function onTouched(hit)
script.Parent.BrickColor = BrickColor.new("Really red")
script.Parent.Deflect:Play()
numOfHits = 1+
if numOfHits == 5 then
script.Parent.CanCollide = false
else
wait(0.05)
script.Parent.BrickColor = BrickColor.new("Lime Green")
end
end
script.Parent.Touched:connect(onTouched)
The script doesn't work but if I get rid of line 6 it works but doesn't count the number of times it's been hit therefore doesn't turn it's NoCollide to false.

1 comment
It works now, thanks! :)