Unable to set camera CFrame?

Hello, and thank you for reading! So, I usually know how to change the player’s camera through CFrame but for some reason it isn’t working now, the only reason I could think of is because I am doing it as soon as the player joined the game, so I wrote this code:

This is in ServerScriptService and fires the event to change the camera as soon as the player joins.

game.Players.PlayerAdded:Connect(function(plr)
	game.ReplicatedStorage.IntroEvent:FireClient(plr)
end)

This is in StarterPlayerScripts and changes the camera, or at least should be…

game.Loaded:Wait()
local camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer

game.ReplicatedStorage.IntroEvent.OnClientEvent:Connect(function()
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = game.Workspace.CameraPart.CFrame
end)

As you can see in the first line I wait for the game to load, and every other time I have done this it works.

If it is useful, I got this warning: https://devforum.roblox.com/t/activatecameracontroller-did-not-select-a-module-warning-in-cameramodule-lua/898641

Thank you for reading!

1 Like

If you need this to run once when the player joins, and it’s local to the player, then there is no need to have the server involved. The following code should suffice, in a LocalScript:

game.Loaded:Wait()

local camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer

camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = workspace:WaitForChild("CameraPart").CFrame

Remember, it’s almost always important to use WaitForChild when retrieving things in workspace from the client. You don’t know if they’re loaded yet!

1 Like

Server script:

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function()	
		game.ReplicatedStorage.IntroEvent:FireClient(plr)
	end)
end)

You should wait for the character to load since that’s when the camera is actually in use.

local camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer

game.ReplicatedStorage.IntroEvent.OnClientEvent:Connect(function()
wait()
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = game.Workspace.CameraPart.CFrame
end)

The wait() seems to fix the activatecameracontroller-did-not-select-a-module-warning-in-cameramodule warning

1 Like

This worked! Thank you so much.

1 Like