Change Camera on Join

I’m trying to make the camera shift to a part MenuCamera when the player joins, kind of like a menu.

Anyway, I can’t seem to make it work.

LOCAL SCRIPT IN STARTERGUI:

local Cameras = workspace.Cameras
local MenuCamera = Cameras.MenuCamera
local CurrentCamera = workspace.CurrentCamera
--
local Players = game:GetService("Players")
--
Players.PlayerAdded:Connect(function(player)
	--
	print("Player has entered " .. player.Name)
	CurrentCamera.CameraType = Enum.CameraType.Scriptable
	CurrentCamera.CFrame = MenuCamera.CFrame
	--
end)

It might be because PlayerAdded can’t be used in a local script but I’m unsure.

Any help would be appreciated!

Client scripts will run immediatly when the source Code is replicated i guess. So I would wait until the Game ist loaded and then just move the camera.

If not game:IsLoaded() then
   game.Loaded.wait()
end

local Cameras = workspace.Cameras
local MenuCamera = Cameras.MenuCamera
local CurrentCamera = workspace.CurrentCamera

	--
	
CurrentCamera.CameraType = Enum.CameraType.Scriptable
CurrentCamera.CFrame = MenuCamera.CFrame


This unfortunately didn’t solve the problem, I tried this, and with the PlayerAdded function.

Thank you though!

Does it throw any errors? And if yes which? Or is just nothing happening?

I made a typo in my code.
Replace in line 2 “game.Loaded.wait()” with “game.Loaded:Wait()”

No there aren’t any errors, but I’ll try this.

That didn’t work either, I’m confused.

Sorry, do you want to get the camera immediately after the local player joins?
If so, why are you waiting for the local player to join (they are already in-game)?

How else would I make the Camera’s CFrame to the part once the player joins?

If the script ran as a local script that means that the player has joined, no need to put the player added or something. This is not a server script…

I see, so I would just put:

CurrentCamera.CameraType = Enum.CameraType.Scriptable
CurrentCamera.CFrame = MenuCamera.CFrame

replacing the PlayerAdded function? (It doesn’t work)

Yes.
But keep in mind that the current camera could be nil so I’d recommend making a second backup like or WaitForChild("Camera")

Your script could be:

local Cameras = workspace:WaitForChild("Cameras")
local MenuCamera = Cameras.MenuCamera
local CurrentCamera = workspace.CurrentCamera or workspace:WaitForChild("Camera")

CurrentCamera.CameraType = Enum.CameraType.Scriptable
CurrentCamera.CFrame = MenuCamera.CFrame

It is maybe because it is in StarterGui as you’ve said earlier. Try putting it in StarterPlayerScripts

The WaitForChild() didn’t seem to do anything, and changing its location to StarterPlayerScripts also did nothing.

There also aren’t any errors which is weird.

+1.
did you try putting a print after the script code?

local Cameras = workspace:WaitForChild("Cameras")
local MenuCamera = Cameras.MenuCamera
local CurrentCamera = workspace.CurrentCamera or workspace:WaitForChild("Camera")
--
local Players = game:GetService("Players")
print("Went through locals")
--
CurrentCamera.CameraType = Enum.CameraType.Scriptable
CurrentCamera.CFrame = MenuCamera.CFrame
print("Went through code")

It printed both prints although it’s not changing the camera.

I just added wait(1) before the CurrentCamera.CameraType = Enum.CameraType.Scriptable and it worked. Thanks for your help! It works now.

1 Like

I was about to demonstrate the issue :sweat_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.