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

LoadPlayer function help?

Asked by 8 years ago

So ive created a respawn script that loads the character after death. The script is local (located in the StarterPlayerScripts folder).

player = game.Players.LocalPlayer
function PlayerDied()
    wait(2)
    player:LoadCharacter()
    player.Character.Torso.CFrame = CFrame.new(0,20,0)
end
player.Character.Humanoid.Died:connect(PlayerDied)

The only problem is that after the character is loaded and his/her position is set to a specified location, the player is teleported to the players defualt spawn location. There are no direct errors, instead I need away to prevent the player from being teleported to the spawn. If you dont understand, please test this for yourself.

0
I don't understand why you don't try and do it the other way around. Have a spawn location where you want them first and then if they need moving after that then teleport them? Uroxus 350 — 8y
0
MrLegoman900 it's the same reason why people create complex scripts for simple things. If you suggest a new idea, put it in the answers. Otherwise, shut up and walk a way from it. I'm tired of getting comments like these. Idiot. LateralLace 297 — 8y

1 answer

Log in to vote
2
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
8 years ago

Problem

Your problem sadly goes deeper than the CFraming Torso Position. In the Notes of the LoadCharacter wiki page it states;

  • This item should be used in a Script to work as expected online.

So you're going to have to make a Server Side script.


Solution

For the final solution script we want to change the CharacterAutoLoads property to false.

Once completed with that the PlayerAdded event will need to be connected to.

We will want to take the Player and connect them to the CharacterAdded event, that way we can connect to their humanoid when we first go to load their character.

In the CharacterAdded function we will want to make sure Humanoid loads, so we'll have a repeat loop keep waiting until Humanoid does exist.

Once we find out that Humanoid exists, then we'll connect it to the Died event.

When the Died event fires, the script will wait the two seconds you desired and then load the character.

Once done with that we'll want to see if the Character's Torso exists so we will establish a repeat loop again to wait until it loads. You will then want to change the CFrame position of the Torso.

Also, do keep in mind that CFrame requires Vector3 values, so you would want to encase the values in Vector3.new(). It will look something like in the script below.

game:GetService('Players').CharacterAutoLoads = false

game:GetService('Players').PlayerAdded:connect(function(Player)
    Player.CharacterAdded:connect(function(Character)
        repeat wait() until Character:FindFirstChild('Humanoid')
        Character.Humanoid.Died:connect(function()
            wait(2) --Prefered time.
            Player:LoadCharacter()
            repeat wait() until Player.Character:FindFirstChild('Torso')
            Player.Character.Torso.CFrame = CFrame.new(Vector3.new(0,20,0))
        end)
    end)
    Player:LoadCharacter() --When the player joins the game, this will be the first time they load.
end)

Sources: ROBLOX Wiki

Hopefully this helped, if so hit the upvote button. If this answered your question hit the Accept Answer button. If you have any questions or comments, please leave them in the comments below.
0
Ugh I hate server - side scripts when your trying to locate and control a player. Anyways thx for the script!!! LateralLace 297 — 8y
Ad

Answer this question