HumanoidRootPart CFrame not changing on character spawn

Sample scenario but the title explains it all

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!

2 Likes

Why are you trying to change the HumanoidRootPart CFrame?

Are you trying to teleport the whole character, because you would have to use PivotTo() for that to work:

character.HumanoidRootPart.CFrame = ... --Not correct.

character:PivotTo(...) --Correct.

Also, you can wrap it around a RunService.Heartbeat event instead of a task.wait().

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!

Bump - I’m timed on this project so It’d be great if anyone is able to help out :slight_smile:

Try this:

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)

Why are you doing playeradded to call the event to move the player and not characterAdded?

He needs to define the player first to use that function.

1 Like

Hmm, you should add prints to see what exactly the script does like print “teleported” or print the cframe, etc

I’m using CharacterAppearanceLoaded (Which is characteradded but makes sure all parts are available to reference)

I’ve done this and everything prints, thought I am not teleported unless I add the wait.

This did not work either, unfortunately.

Idk if this is work but you can do

repeat
HumanoidRootPart.CFrame = Part.CFrame
until HumanoidRootPart.CFrame = Part.CFrame

Im on phone and not sure if it works

This is basically your task.wait, it repeats until the humanoidrootpart cframe is equals to the part cframe

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)

uhhhh MoveTo dosent teleport the player, it just walks the player’s character to that point…

I think you might be talking about character.Humanoid:MoveTo()

Unfortunately this is pretty much identical to what I’m doing and doesn’t work either.

oh right, sorry I should have paid attention

Alright I think I might have found the solution.

local RunService = game:GetService("RunService")

game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(character)
print("character added")
end)

local part = workspace.Part

plr.CharacterAppearanceLoaded:Wait()

RunService.Stepped:Wait()

plr.Character:SetPrimaryPartCFrame(part.CFrame)
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)