Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Respawn script not working correctly?

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.

5 comments

0

Did you disabled the normal character load?

0

Yes I did. However, when I tried that, it made the character not load in when they first spawned.

1

You should have a script that disables the normal character load after the character is first added

0

Try adding a loop and check wether the characters health ~= 0 it should work.

0

I added a script that disables the CharacterAutoLoads. It still doesn't work. Any further suggestions?

1 answer

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.