So once I change either the character value or parent it gets teleports up in the air

So I have a script that sets the players character to a new one. And it keeps getting teleported up in the air after I set either the players.Character
or the characters parent.
Can anyone tell me why?

event.OnServerEvent:Connect(function(player)
	local teams = game:GetService('Teams')
	
	if player.Team == teams.Menu then -- make sure they are in the menu
		
		player.Team = teams.Playing -- make there team playing
		local lastChar = player.Character
		-- load the player in
		local char = player.Profile.Character.Value.Char:Clone()
		
		
		
		
		player:LoadCharacter()
		
		char.PrimaryPart.CFrame = lastChar.PrimaryPart.CFrame
		char.PrimaryPart.Anchored = false
		
		wait()
		
		player.Character = char
		player.Character.Parent = workspace
		
		lastChar:Destroy()
		
		print('Character loaded')
		
	else
		print('Um how did you do this???')
	end
end)
1 Like

the error could be that you’re calling player:LoadCharacter() and then setting the new cframe. LoadCharacter() runs asynchronously and the last step in loading event order is moving the character to the spawn location. So what I think could be happening is that you’re calling LoadCharacter(), then setting a new cframe but then the cframe gets overriden by LoadCharacter() at the last stage. Try removing LoadCharacter() and just setting the new player character and changing the cframe

I tried changing some of the stuff. I noticed that when I set the character to the new char, it then teleports them up in the air

btw the last chars position is where it should be

I also did what you said and it still didn’t work

player.Team = teams.Playing -- make there team playing
local lastChar = player.Character
local lastCharCFrame= lastChar:GetPivot()
-- load the player in
local char = player.Profile.Character.Value.Char:Clone()

char.PrimaryPart.CFrame = lastChar.PrimaryPart.CFrame
char.PrimaryPart.Anchored = false

player.Character = char
player.Character.Parent = workspace
player.Character:PivotTo(lastCharCFrame)
lastChar:Destroy()

print('Character loaded')

Maybe try this?

Tried this its still moving the player, I wonder why this is happening

I figured it out. If I change the spawn location it just for some reason stops teleporting them

		local spawnPoint = workspace.Spawns:GetChildren()[1]
		player.RespawnLocation = spawnPoint
		player:LoadCharacter()
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.