Trying to respawn a player when they die to a part location

Hi,

I am trying to respawn a player when they die to a part location, I have the server script below which does not error but when a player dies they get put on the SpawnPoint, not the part?

Does anyone know what I am doing wrong? thanks

game:GetService('Players').PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").Died:Connect(function()
			print("Spawning to last SpawnPoint")
			local DataManager = require(game.ServerStorage.DataManager)
			local Profile = DataManager:GetData(player)
			player.Character.HumanoidRootPart.Position = Profile.Data["CurrentStagePos"]
			end)
		end)
	end)

.Died event will not wait until the player respawns, so if you try to change the player’s position before it can respawn, it will do nothing. You will just need .CharacterAdded for this.

game:GetService('Players').PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		print("Spawning to last SpawnPoint")
		local DataManager = require(game.ServerStorage.DataManager)
		local Profile = DataManager:GetData(player)
		player.Character:MoveTo(Profile.Data["CurrentStagePos"])
	end)
end)
2 Likes