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

How to decrease all players health?

Asked by 4 years ago

How would I SLOWLY decrease all players health?

I know I would use

1i,v in pairs do()

and change all humanoids

1.Health

value. But I don't know how to go about that.

3 answers

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

As you knew, iterate through each player in the game via the :GetPlayers() function of Players.

Allocate their Characters' Humanoid Instance, then begin decreasing their health through a loop.

You must do this on a separate thread, as it will yield the pairs iterator from continuing forward with initiating the other Player's health decrement.

01local Players = game:GetService("Players")
02 
03 
04for _, Player in pairs(Players:GetPlayers()) do
05    local Character = Player.Character
06    if (Character) then
07        ---------------
08        local Humanoid = Character.Humanoid
09        ---------------
10        spawn(function()
11            ---------------
12            while (Humanoid.Health > 0) do
13                Humanoid.Health -= 1
14                ---------------
15                wait(--[[Time]])
16            end
17        end)
18    end
19end
Ad
Log in to vote
1
Answered by 4 years ago

Hey! I can't write scripts for you but, I reccomend looking at https://developer.roblox.com/en-us/api-reference/property/Humanoid/Health and https://blog.roblox.com/2012/05/using-wait-wisely/

Log in to vote
0
Answered by
R_alatch 394 Moderation Voter
4 years ago
Edited 4 years ago

Use a for loop and loop through the array of players using :GetPlayers(). Keep in mind you must use a different thread for each player, which can be done using spawn, coroutine.wrap, or coroutine.resume(coroutine.create()).

01for _, player in ipairs(game:GetService("Players"):GetPlayers()) do
02    local character = player.Character
03 
04    if not character then
05        continue
06    end
07 
08    local humanoid = character.Humanoid
09 
10    coroutine.wrap(function()
11        while humanoid and humanoid.Health > 0 do
12            humanoid.Health -= 1
13 
14            wait(n)
15        end
16    end)()
17end

Answer this question