I am a newbie to scripting, and I am having trouble looping the script Azarth helped me with. I have tried many times with different types of loops, but nothing happens. I am stuck and have asked for help on the forums but nobody responded so I would appreciate help.
for i=1, 10 do local player = game.Players.LocalPlayer local character = player.Character local humanoid = character:WaitForChild("Humanoid") local depletionAmount = 10 repeat until i<1 local function healthDeplete() local currentHealth = humanoid.Health -- wait(1) local newHealth = currentHealth - depletionAmount humanoid.Health = newHealth end healthDeplete()
while true do humanoid.Health = humanoid.Health - depletionAmount wait() end
while true loop will never end unless script was removed (EDIT: or command
break was used)
Also it's not necessary to make
local newHealth and
currentHealth. You can directly interact with humanoid health.
Try making the
repeat until i<1
into a different form of loop, or make the function non-local
If this helped you, dont forget to accept the answer