So, I am trying to make a script so that every second the player touches the part specified, it loses 10 health. But every time I try the code, it only seems to do it once. I don't know what's going on, if it's all the if/repeat/while commands, but it only does it once. Please help?
function onTouch(part)
local humanoid = part.Parent:FindFirstChild("Humanoid")
local x = 100
while (humanoid ~= nil) do
repeat -- basically repeat
humanoid.Health = (x - 10) -- damage the humanoid
wait(2.0) -- wait time for another damage count
until( x == 0 ) -- the condition that the code must be in for the repeat to stop
end
end
script.Parent.Touched:connect(onTouch)
I don't know what's going on. Sorry for having such an unorganized script, I'm new.

1 comment
Thanks for the advice! Now the script is working just fine!