Hello.
I am currently attempting to make a script where if the player dies, and respawns, it makes the player invisible. It detects when the player dies and when the character is added after it died, however it does not make it invisible.
Here's my script (ServerScript):
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid.Died:Connect(function()
Player.CharacterAdded:Wait()
for _, BodyParts in pairs(Character:GetChildren()) do
if (BodyParts:IsA("BasePart")) then
BodyParts.Transparency = 1
end
end
Character.Head.face.Transparency = 1
for _, CharacterAssets in pairs(Character:GetChildren()) do
if (CharacterAssets:IsA("Accessory")) then
CharacterAssets.Handle.Transparency = 1
end
end
end)
end)
end)
I am not sure what the cause of this is, and would like some help. Thanks!

7 comments
Remove line 7, it's redundant and is likely causing your issue.
That does work, I have tested it, however it makes it invisible as soon as the character dies and respawns visible
This is also because you linked the callback to its death. The CharacterAdded signal fires upon respawning, you do not need to detect death.
While that may be true, it would also fire as soon as a player would join the game
After CharacterAdded:Wait() you are still indexing the old character, you need to make variable of newly added character as previous one is already parented to nil
Should CharacterRemoving be used in this situation?
i don't think so, single line as creating variable for new character like local Character = Gamer.CharacterAdded:Wait() would be good