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)
There are two answers to this
The first answer assumes that CharacterAdded works properly, and just rearranges your code
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.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.Value; end) end) player:LoadCharacter() player.Character.Torso.CFrame = CFrame.new(Vector3.new(0,5,0)) + player.SpawnLocation.Value end)
The second answer assumes that CharacterAdded is broken, and tries to get around it by cheating.
game.Players.CharacterAutoLoads = false game.Players.PlayerAdded:connect(function(player) local bindPlayerDeath bindPlayerDeath = function() wait(1.8) player:LoadCharacter() player.Character.Torso.CFrame = CFrame.new(Vector3.new(0,5,0)) + player.SpawnLocation.Value player.Character:WaitForChild("Humanoid").Died:connect(bindPlayerDeath); end; 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 print("hi") repeat wait() until char:FindFirstChild("Humanoid") ~= nil char.Humanoid.Died:connect(bindPlayerDeath); end)