Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can i loop this health depleting script?

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()

2 answers

✓ Accepted answer

Hi.

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.

12 comments

0

No, that is false that while true loops do not stop. You can use break.

0

Sorry, my bad :D

0

Thanks for the help dude but the health likes to regenerate and i'm not sure how to stop this :P

0

Ohh

0

You have to remove the healing script form player

0

humanoid.Parent.Health:Destroy() -- this will remove the healing effect

0

Thanks but when i put this in the script, it only depletes health one time. do i need to put in a seperate script?

0

Add this script to StarterPlayer -> StarterCharacterScripts

0

The script is already in that folder, do i need to put it in a specific part of the script? Also thanks for putting up with my newbie questions

0

You have to replace the loop code with humanoid.Parent.Health:Destroy() this one.

0

what do you mean by loop code? the while true do humanoid.health = humanoid. health - depletionAmount wait() end?

0

I messaged you, go check your inbox ;P

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

This discussion is preserved as it was. New answers, comments, and votes are closed.