How would I SLOWLY decrease all players health?
I know I would use
1 | i,v in pairs do () |
and change all humanoids
1 | .Health |
value. But I don't know how to go about that.
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.
pairs
iterator from continuing forward with initiating the other Player's health decrement.01 | local Players = game:GetService( "Players" ) |
02 |
03 |
04 | for _, 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 |
19 | end |
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/
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())
.
01 | for _, 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 )() |
17 | end |