Camera won't update CFrame when the player joins the game

What’s wrong

Whenever I join the game, I can’t seem to get the camera to update to the given CFrame coordinates.

Info

This is a local script that I’ve put into StarterGui. It’s meant to be for when the player joins the game only.

Code

local Player = game.Players.LocalPlayer
if not Player.Character then
	Player.CharacterAdded:Wait()
end

local Scene = workspace:WaitForChild("Scene")
local SceneFocus = Scene:WaitForChild("SceneFocus")
local ScenePosition = Scene:WaitForChild("ScenePosition")

local Camera = workspace.CurrentCamera
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = CFrame.new(ScenePosition.CFrame.p, SceneFocus.CFrame.p)
1 Like

Any error messages displayed in console?

1 Like

The same script worked fine for me, I placed it in “StarterPlayerScripts”.

image

Nope there’s no errors, I don’t know what the issue is. If I wait 3 seconds however then it fixes the problem. I think the issue could be that the script runs everything before it’s able to load?

If that’s the problem though idk how to fix I tried

repeat task.wait() until game:IsLoaded()
1 Like

Yeah actually maybe that’s a better idea I’ll try placing it there.

Instead of that repeat until loop use the following.

if not game:IsLoaded() then
	game.Loaded:Wait()
end

This is just general advice.

you could do

repeat task.wait() until workspace.CurrentCamera ~= nil
-- code

not sure if it’ll work.

2 Likes

Hm I’m not sure how it worked for you, because it’s not working for me at all even in StarterPlayerScripts. I added prints, and it seems to print everything below it so I know the script can do other stuff afterwards.

Try it in a blank baseplate with the bare essentials (script, scene stuff).

That seems more like a workaround rather than a solution.

well the main reason why cframe wont update is because the camera hasn’t loaded in yet(pretty sure why). Have you even tried it yet? Stopping any code from erroring/not working is a workaround technically

image

image

Removed all the other stuff I used before, the camera still doesn’t seem to want to CFrame.

That model needs to be named “Scene” as referenced in the script.

I changed the name earlier to Scene for this thread it just sounded more accurate. But in the game it’s named Menu so that’s not the solution.

I just updated the code though so this is what it looks like now:

local Player = game.Players.LocalPlayer
if not Player.Character then
	Player.CharacterAdded:Wait()
end

local Scene = workspace:WaitForChild("Scene")
local SceneFocus = Scene:WaitForChild("SceneFocus")
local ScenePosition = Scene:WaitForChild("ScenePosition")

local Camera = workspace.CurrentCamera
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = CFrame.new(ScenePosition.CFrame.p, SceneFocus.CFrame.p)

local Gui = script:WaitForChild("Menu")
local Play = Gui:WaitForChild("Play")
local GameLogo = Gui:WaitForChild("GameLogo")

Gui.Parent = Player.PlayerGui
GameLogo.Rotation = -20
Gui.Enabled = true

try doing

local Player = game.Players.LocalPlayer
repeat task.wait() until game:IsLoaded() or workspace.CurrentCamera ~= nil

local Scene = workspace:WaitForChild("Scene")
local SceneFocus = Scene:WaitForChild("SceneFocus")
local ScenePosition = Scene:WaitForChild("ScenePosition")

local Camera = workspace.CurrentCamera
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = CFrame.new(ScenePosition.CFrame.p, SceneFocus.CFrame.p)

local Gui = script:WaitForChild("Menu")
local Play = Gui:WaitForChild("Play")
local GameLogo = Gui:WaitForChild("GameLogo")

Gui.Parent = Player.PlayerGui
GameLogo.Rotation = -20
Gui.Enabled = true

Tried this already, just did it again it doesn’t seem to do anything. Here’s the code:

local Player = game.Players.LocalPlayer
repeat task.wait() until game:IsLoaded() 

local Scene = workspace:WaitForChild("Scene")
local SceneFocus = Scene:WaitForChild("SceneFocus")
local ScenePosition = Scene:WaitForChild("ScenePosition")

local Camera = workspace.CurrentCamera
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = CFrame.new(ScenePosition.CFrame.p, SceneFocus.CFrame.p)

maybe try again with the camera instead

local Player = game.Players.LocalPlayer
repeat task.wait() until workspace.CurrentCamera ~= nil

local Scene = workspace:WaitForChild("Scene")
local SceneFocus = Scene:WaitForChild("SceneFocus")
local ScenePosition = Scene:WaitForChild("ScenePosition")

local Camera = workspace.CurrentCamera
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = CFrame.new(ScenePosition.CFrame.p, SceneFocus.CFrame.p)

I tried that too, I’m not sure what the issue is the script just doesn’t want to load the cframes unless I wait 3 seconds for some reason. But I don’t want it to wait 3 seconds it’s unreliable and everyone loads in at different speeds.

The CurrentCamera property is not nil from the get-go.

didn’t know that thx for the information