Ad
Log in to vote
0

How can i loop this health depleting script?

Asked by 9 days 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()

Hi.

Looks like you're using an ad blocker.

That's fine...

No, it really is.

Just, I mean, we put a lot of work into this site, you know?

It would be really really appreciated if you would turn off your ad blocker for our website...

We tried really hard to make our ads as unobtrusive as possible.

If you really hate ads, would you consider a $2 donation via Patreon?

Here's the link.

We love you. We hope you love us too.

.

..

...

Now back to your regularly scheduled Scripting Helpers....

...

..

.

2 answers

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



Ad