Scriptable Camera Issue

Hi,

I am setting the camera’s cframe to a certain position for my main menu. I have been running into some issues with changing the camera type to scriptable. Here is my code.

local camera = game.Workspace.Camera

camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = game.Workspace.Part.CFrame

This does not work. Instead the camera stays with the character. But, if I simply add wait(), the issue is solved.

local camera = game.Workspace.Camera

wait()

camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = game.Workspace.Part.CFrame

I just find this very odd because I have seen other people’s code who are able to change the camera type without using this wait. Even though this technically works, I read this : Avoiding wait() and why , which said to avoid wait. Using wait() just seems a bit hacky and I’d rather try to figure the cause of this issue.

Remember to use CurrentCamera instead of camera, maybe that will fix the issue…

Maybe change line 1 to

local camera = game.Workspace:WaitForChild("CurrentCamera")

Maybe this has something to do with Roblox’s player scripts? Could try waiting for the player to load and then move the camera and see if that fixes the problem.

This did not work, unfortunately.

This code is in starterplayerscripts. Wouldn’t the player already be loaded in once this runs?

How about try putting it in StarterCharacterScripts to see if it makes any sort of difference?

This works! My only issue is that I am trying to run this only when the player first joins. Are there any potential ways I can accomplish that while having the script in startercharacterscripts?

Honestly I have no clue, StarterPlayerScripts might be quicker due to the fact that it runs whenever a player first joins the game, whileStarterCharacterScripts only runs whenever the Character is visible to the workspace? I’m just guessing

You could also try doing a PlayerAdded function in ServerScriptService (Just for experimentation)

If you only need to run this script once then an alternative method would be to just put the LocalScript in ReplicatedFirst. You can use the following code to wait for the character to spawn.

local Player = game:GetService('Players').LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()

print('Do your camera stuff here, hopefully theres nothing wrong with the timing?')