Add a part into workspace named “Part” & add this script into ServerScriptService for a repro - You’ll find your character not spawned at the part as you’d expect.
local Players = game:GetService("Players")
local function SpawnPlayer(Player: Player, Character: Model)
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local Part = workspace.Part
HumanoidRootPart.CFrame = Part.CFrame
end
local function PlayerAdded(Player: Player)
Player.CharacterAppearanceLoaded:Connect(function(Character: Model)
SpawnPlayer(Player, Character)
end)
end
Players.PlayerAdded:Connect(PlayerAdded)
You can get this to (very unreliably & by chance) work if you put a task.wait() above this line as such:
task.wait()
HumanoidRootPart.CFrame = Part.CFrame
This is something I do not plan on using as it is both very unreliable and leaves me extremely dissatisfied with it. My question is how would I get this to work without unreliable & chanceful methods like the task.wait() one I specified above. Thanks!
I’ve used HumanoidRootPart.CFrame for years & was blissfully unaware :PivotTo() existed, so thanks & ill check it out when I get home!
To answer your question - I’m teleporting players to their own little rooms for my game, the above scenario was just to reproduce the problem.
This part, however also leaves me with a hacky mess (or so I feel, correct me if I’m wrong). I don’t want to have to wait for my characters HumanoidRootPart if it (seemingly) already exists. You can print out the HumanoidRootPart in the function, before the teleport occurs and it provides proof that my HumanoidRootPart exists - so why can’t I just teleport it? Will :PivotTo() fix this issue (Nor sure why it would but hey, if it works I can’t complain!) or do I seriously have to wait (for seemingly zero reason) to teleport the character. Thanks!
local Players = game:GetService("Players")
local function SpawnPlayer(Player: Player, Character: Model)
Character:MoveTo(Part.Position)
end
local function PlayerAdded(Player: Player)
Player.CharacterAdded:Connect(function(Character: Model)
SpawnPlayer(Player, Character)
end)
end
Players.PlayerAdded:Connect(PlayerAdded)
Okay. I’ve made my own script , see if this works.
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(character)
local part = workspace.Part
character:MoveTo(part.Position)
end)
end)
I see no reason why this wouldn’t work, seems like a roblox bug, something messing with it or its something out of my knowledge, I rewrote the code and it works now:
game.Players.PlayerAdded:Connect(function(player)
local character
character = workspace:WaitForChild(player.Name)
character:WaitForChild("HumanoidRootPart").CFrame = workspace.Part.CFrame
player.CharacterAdded:Connect(function(character)
character:WaitForChild("HumanoidRootPart").CFrame = workspace.Part.CFrame
end)
end)