Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I rotate the player on spawn correctly?

Asked by 3 years ago
Edited 3 years ago

I wanted the player to rotate when it spawns by scripting,rather than just rotating spawn location. but Changing HumanoidRootPart (PrimaryPart)'s CFrame only worked few secs later the character spawned. Even with WaitForChild function,it didnt work but not occured error. Are there any good ways to make it rotate when spawned,but not using wait() call?

local Players = game:GetService("Players")
local spawnlocation = workspace.SpawnLocation
game.Players.PlayerAdded:Connect(function (plr)
    plr.CharacterAdded:Connect(function ()
        print(plr.Name)
        local rootpart = plr.Character:WaitForChild("HumanoidRootPart")
        rootpart.CFrame =               spawnlocation.CFrame*CFrame.new(0,1,0,math.rad(10),math.rad(20),math.rad(30),1) -- this one doesnt work
wait(3)
rootpart.CFrame =                       spawnlocation.CFrame*CFrame.new(0,1,0,math.rad(10),math.rad(20),math.rad(30),1) -- this one works
    end)
end)

Answer this question