I’ve looked for a long time for a problem similar to mine on the forum and while there’s a lot of questions similar to mine, the solutions they have doesn’t seem to work for mine.
I’m trying to make a players character teleport to an available baseplate when they join the game and here’s the code.
local function TycoonStart(player)
local ChosenTycoon = workspace.Tycoons:FindFirstChild("Tycoon")
if ChosenTycoon then
print("True") -- debugging, works fine
ChosenTycoon.Name = player.Name
local character = player.CharacterAdded:Wait() -- doesn't work
character:WaitForChild("HumanoidRootPart") -- doesn't work
wait(3) -- oh now it works?
character:SetPrimaryPartCFrame(ChosenTycoon.SpawnLocation.CFrame)
print(character)
else
DataManager.RemoveProfile(player, "Failed to find available tycoon base.")
end
end
game.Players.PlayerAded:Connect(TycoonStart)
I’m waiting for the character to fully spawn using CharacterAdded:Wait() before teleporting the character but it’s not yielding enough.
How to solve inconsistent character teleporting on player join?
Edit: I found out the problem
From the developer page
- “Note, CharacterAdded fires when the Character is assigned to the
Player
, which is before the Character is parented to theWorkspace
”