Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

LocalScript can't find Workspace.CurrentCamera?

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?

5 comments

0

CurrentCamera isn't an actual object, better try workspace.Camera

0

That fixes the infinite yield problem, but I still can't change the camera rotation.

0

Search on google CFrames roblox and look if something is helpful, you can also make a part for every stage and change camera CFrame to it

0

I have tried both of those things.

0

Then try using tween service

3 answers

✓ Accepted answer

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?

This discussion is preserved as it was. New answers, comments, and votes are closed.