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

LocalScript can't find Workspace.CurrentCamera?

Asked by
AronYstad 101
2 years ago

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?

0
CurrentCamera isn't an actual object, better try workspace.Camera SuperPuiu 497 — 2y
0
That fixes the infinite yield problem, but I still can't change the camera rotation. AronYstad 101 — 2y
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 SuperPuiu 497 — 2y
0
I have tried both of those things. AronYstad 101 — 2y
0
Then try using tween service SuperPuiu 497 — 2y

3 answers

Log in to vote
0
Answered by
3_Ii 13
2 years ago

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

Ad
Log in to vote
0
Answered by
SuperPuiu 497 Moderation Voter
2 years ago

CurrentCamera is a reference to player's camera, so you cant use WaitForChild or FindFirstChild. Use workspace.Camera for that.

Log in to vote
0
Answered by
AronYstad 101
2 years ago

So I fixed it by adding wait() to the start. Can anyone explain why this fixed the problem?

Answer this question