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)
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
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')