When I try to morph the player character into another model everything goes fine except for my character rotation script, which breaks because "player.character is null". this is the code for the character swap:
local oldChar = plr.Character
local newChar = rs:WaitForChild("CharacterModels"):WaitForChild(arg1):Clone()
newChar.Name = plr.Name
newChar.HumanoidRootPart.Anchored = false
newChar:SetPrimaryPartCFrame(oldChar.PrimaryPart.CFrame)
oldChar:Destroy()
plr.Character = newChar
newChar.Parent = workspace
and this is the code for the rotation
local cam = workspace.CurrentCamera
local plr = game:GetService("Players").LocalPlayer
game:GetService("RunService").RenderStepped:Connect(function()
local char = plr.Character
if char then
local rootPart = char:WaitForChild("HumanoidRootPart")
if rootPart then
rootPart.CFrame = CFrame.new(rootPart.CFrame.p, rootPart.CFrame.p + Vector3.new(cam.CFrame.LookVector.X,0,cam.CFrame.LookVector.Z))
end
end
end)