So I'm making an obby, and I want the camera to face the next stage when you respawn. So I tried to add this in a local script in StarterCharacterScripts:
local Camera = game.Workspace.CurrentCamera if game.Players.LocalPlayer.leaderstats.Stage.Value > 7 and game.Players.LocalPlayer.leaderstats.Stage.Value < 19 then Camera.CFrame = script.Parent.HumanoidRootPart.CFrame * CFrame.Angles(math.rad(90),0,0) print("success") end
(The angle isn't the actual angle. I just tried a few random ones.) That did nothing, so I tried changing it to
local Camera = game.Workspace:WaitForChild("CurrentCamera") if game.Players.LocalPlayer.leaderstats.Stage.Value > 7 and game.Players.LocalPlayer.leaderstats.Stage.Value < 19 then Camera.CFrame = script.Parent.HumanoidRootPart.CFrame * CFrame.Angles(math.rad(90),0,0) print("success") end
But then it said "Infinite yield possible on 'Workspace:WaitForChild("CurrentCamera")'". Why can it not find CurrentCamera?
CurrentCamera is an object value of workspace, which is set to workspace.Camera by default
For your previous script, maybe CameraType or CameraSubject is interfering with your scripting, try changing it around
CurrentCamera is a reference to player's camera, so you cant use WaitForChild or FindFirstChild. Use workspace.Camera for that.
So I fixed it by adding wait() to the start. Can anyone explain why this fixed the problem?