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

How can i loop this health depleting script?

Asked by 6 years ago

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

Log in to vote
0
Answered by
deris88 146
6 years ago
Edited 6 years ago

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.

0
No, that is false that while true loops do not stop. You can use break. hiimgoodpack 2009 — 6y
0
Sorry, my bad :D deris88 146 — 6y
0
Thanks for the help dude but the health likes to regenerate and i'm not sure how to stop this :P jakobgomez6 -3 — 6y
0
Ohh deris88 146 — 6y
View all comments (8 more)
0
You have to remove the healing script form player deris88 146 — 6y
0
humanoid.Parent.Health:Destroy() -- this will remove the healing effect deris88 146 — 6y
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? jakobgomez6 -3 — 6y
0
Add this script to StarterPlayer -> StarterCharacterScripts deris88 146 — 6y
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 jakobgomez6 -3 — 6y
0
You have to replace the loop code with humanoid.Parent.Health:Destroy() this one. deris88 146 — 6y
0
what do you mean by loop code? the while true do humanoid.health = humanoid. health - depletionAmount wait() end? jakobgomez6 -3 — 6y
0
I messaged you, go check your inbox ;P deris88 146 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

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

Answer this question