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

Character not moving to the place its supposed to when it respawns?

Asked by
halwa 11
7 years ago

I've done this but its not working? no errors. not working in studio nor server?

Player.CharacterAdded:connect(function()
    Player.Character:MoveTo(GetTycoon().BasePlate.Position + Vector3.new(0,10,0))
end)
0
GetTycoon() is a function i made that gets the player's tycoon halwa 11 — 7y

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

Other than the fact that Player wasn't defined in the question, your problem is that the Character has not loaded yet.

You should wait until the HumanoidRootPart has loaded using the WaitForChild function, and then CFrame it.

note: remember to use variables to keep your code clean and concise!
game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:connect(function(c)
        local h = c:WaitForChild("HumanoidRootPart")
        local target = GetTycoon().BasePlate.Position
        local offset = Vector3.new(0,10,0)
        h.CFrame = CFrame.new(target + offset)
    end)
end)
Ad

Answer this question