I'm working on a script that detects when a player's health has reached 0. Any way to do this? This is what I tried.
local player = game.Players:GetPlayers()
and
elseif player.Character.Humanoid.Health == 0 then print (player.Name)" has died!" end
Any help is appreciated.
Use the .Died event! It is fired after a character has entered the dead state, usually when their health reaches 0. Nonetheless, your player variable is a table of players, which wouldn't work!
Just got the following code from this wiki article.
You'll want to put this in a script in ServerScriptStorage. Since we're using a ServerSide script, it can at times be difficult to define the player....As such, a quick and efficient way to accomplish such a task would be to use both the playeradded event and the characteradded event to then be able to link to the players humanoid (The .Died event fires off of the humanoid) .
game:GetService('Players').PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) character:WaitForChild("Humanoid").Died:connect(function() print(player.Name .. " has died!") end) end) end)