Hello everyone, very simple question here. I wrote a simple ragdoll script that kills the player and doesn't make them respawn until they press F. (It uses a RemoteEvent ). The script respawns the player and is supposed to make them respawn where they died, but that's where it doesn't work. It makes the player respawn, but doesn't teleport them to where they "died" or ragdolled. The code I'm using is extremely simple, here it is:
game.ReplicatedStorage.Respawn.OnServerEvent:Connect(function(Player) local char = Player.Character local h = Player.Character.Humanoid local spawnpos = char.LowerTorso.Position print("Respawning the player") Player:LoadCharacter() wait(1) char.HumanoidRootPart.CFrame = spawnpos end)
If anyone could help me out, that'd be great! Thanks in advance.
Just fixed it, I ended up having to reassign the character variable after respawning it. Fixed code is:
game.ReplicatedStorage.Respawn.OnServerEvent:Connect(function(Player) local char = Player.Character local h = Player.Character.Humanoid local spawnpos = char.LowerTorso.CFrame print("Respawning the player") Player:LoadCharacter() wait() local newchar = Player.Character newchar:SetPrimaryPartCFrame(spawnpos) end)
Thanks for the suggestions!