Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why is my Humanoid not losing health every 2 seconds like the code describes?

Asked by 4 years ago

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 answer

Log in to vote
0
Answered by 4 years ago

Alright, So the main issue I see is the system is getting the touch function, causing it to create the x variable over and over at a value of 100. Then when the next script subtracts 10, it becomes 90 and stays 90 since it is constantly resetting. What you should do is not have a variable, and instead, just subtract 10 from the Humanoid health. So:

humanoid.Health = humanoid.Health - 10

This should work. Comment if there is still a problem and I will be glad to help!

0
Thanks for the advice! Now the script is working just fine! skeeBarr 14 — 4y
Ad

Answer this question