So I've been trying to re - spawn the player after 1.8 seconds. Everything works fine the first time the player dies, but after that the player doesn't re - spawn at all. The script is server - side, and is located in the Workspace service.
game.Players.CharacterAutoLoads = false
game.Players.PlayerAdded:connect(function(player)
print("hi")
local SpawnLoc = Instance.new("Vector3Value", player)
SpawnLoc.Name = "SpawnLocation"
SpawnLoc.Value = game.Workspace.Spawn.Position
player:LoadCharacter()
player.Character.Torso.CFrame = CFrame.new(Vector3.new(0,5,0)) + player.SpawnLocation.Value
player.Character.Humanoid.Died:connect(function()
print("hi")
wait(1.8)
player:LoadCharacter()
player.Character.Torso.CFrame = CFrame.new(Vector3.new(0,5,0)) + player.SpawnLocation.Value
end)
end)
Is it that the .Died event of the Humanoid is broken or what. ****Now if you do post an answer, explain your script thourally and do not include any complex/unnecessary code that just makes the script longer. THX!!!
--------------EDIT----------------
Reply to MastaJames : So then why wouldn't this work?
game.Players.CharacterAutoLoads = false
game.Players.PlayerAdded:connect(function(player)
print("hi")
local SpawnLoc = Instance.new("Vector3Value", player)
SpawnLoc.Name = "SpawnLocation"
SpawnLoc.Value = game.Workspace.LobbySpawnLocation.Position
player:LoadCharacter()
player.Character.Torso.CFrame = CFrame.new(Vector3.new(0,5,0)) + player.SpawnLocation.Value
player.CharacterAdded:connect(function(char)
print("hi")
repeat wait() until char:FindFirstChild("Humanoid") ~= nil
char.Humanoid.Died:connect(function()
print("hi")
wait(1.8)
player:LoadCharacter()
player.Character.Torso.CFrame = CFrame.new(Vector3.new(0,5,0)) + player.SpawnLocation.Valu
end)
end)
end)

3 comments
You need the CharacterAdded event to encase the Died function. This is due to your character resetting and providing a new humanoid each time you respawn.
So basicly the died event is broken and usluss for my script
No, it's still useful. The problem is that only the first character is being connected to the event. After that, a new one is loaded and needs to be connected to it's own event. By using CharacterAdded, as M39a9am3R suggested, will convienently allow you to do this.