Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Respawn script not working correctly?

Asked by 4 years ago

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.

0
Did you disabled the normal character load? Leamir 3138 — 4y
0
Yes I did. However, when I tried that, it made the character not load in when they first spawned. happyhal75 32 — 4y
1
You should have a script that disables the normal character load after the character is first added IAmNotTheReal_MePipe 418 — 4y
0
Try adding a loop and check wether the characters health ~= 0 it should work. JesseSong 3916 — 4y
0
I added a script that disables the CharacterAutoLoads. It still doesn't work. Any further suggestions? happyhal75 32 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

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!

Ad

Answer this question