Hi so before I start Im not using character removed since I want to detect if they die or respawn since I have a morph system it would mess it up
2 Likes
You can go off the humanoid health, just check when the health changes if its 0 and then on a loop wait for a new humanoid with health
2 Likes
but when I removing the players character it would turn the health to 0?
It would just remove so the humanoid health doesnt change. It does mean keeping tabs on the humanoid for if it does change
To check when someone dies, you can listen to it via the .Died event:
Humanoid.Died:Connect(function()
print("Player is dead!")
end)
And to check if a player respawns, you can listen to it via the .CharacterAdded event
player.Character.CharacterAdded:Connect(function(character)
print("Player has respawned/spawned!")
end)
.CharacterAdded also works when the player first spawns into the game.
local Players = game:GetService("Players")
local function PlayerAdded(player)
local function CharacterAdded(character)
print(player.Name, "Character Added")
local humanoid = character:WaitForChild("Humanoid", 5)
if humanoid then
humanoid.Died:Connect(function()
print(player.Name, "Died")
end)
end
end
player.CharacterAdded:Connect(function(character)
CharacterAdded(character)
end)
if player.Character then
CharacterAdded(player.Character)
end
end
Players.PlayerAdded:Connect(PlayerAdded)
for _, player in pairs(Players:GetChildren()) do
PlayerAdded(player)
end
2 Likes
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.