Setting a custom camera when player character is not loaded

How can I set a custom camera when the player’s character has not loaded yet? CharacterAutoLoads is set to false. It made a script clone the screengui into playergui when player joins but it doesn’t work

My starter camera script inside a screen gui in StarterGui

-- Object Referencing
local cameraFolder = game.Workspace:WaitForChild("Cameras")
local starterCamera = cameraFolder:WaitForChild("StarterCamera")
local attackerCamera = cameraFolder:WaitForChild("AttackerCamera")
local defenderCamera = cameraFolder:WaitForChild("DefenderCamera")

local camera = game.Workspace.CurrentCamera

print("Working on it...")

repeat
	camera.CameraType = Enum.CameraType.Scriptable
	task.wait(0.1)
until camera.CameraType == Enum.CameraType.Scriptable
print("Complete")
camera.CFrame = starterCamera.CFrame
2 Likes

Can you also share the script that copies the startergui? It’s also important that the script that copies it is either a local script in ReplicatedFirst, or a server script in ServerScriptService.

3 Likes

It’s server script in ServerScriptService.

-- Global Variables
local Players = game:GetService("Players")
local Teams = game.Teams

Players.PlayerAdded:Connect(function(player)
	print(player.Name.." has joined.")
	script.ScreenGui:Clone().Parent = player.PlayerGui
	print("Done")
end)

It prints Done but not Working on it... and sends

 Infinite yield possible on 'Workspace.Cameras:WaitForChild("StarterCamera")'  -  Studio
  20:51:43.193  Stack Begin  -  Studio
  20:51:43.193  Script 'Players.TheDiamondKing_21.PlayerGui.ScreenGui.CameraHandler', Line 3  -  Studio - CameraHandler:3
  20:51:43.193  Stack End  -  Studio

All the camera parts 100% exist in workspace.

2 Likes

You can check if the script is enabled, and if it is, you can try disabling and enabling it in the server script

1 Like

I did those, but unfortunately it still has the Infinite yeild error, which is odd as I’m using :WaitForChild().

2 Likes

Infinite yields may happen for :WaitForChild() because the child that is being acquired might not be there. You should check if all the camera parts are spelled the same as in the local script

You can try putting print()s in between the :WaitForChild()s to see where the script stops.

1 Like

Oh, I found my issue, they somehow disappear when I join the game, I’ll need to see why the delete themselves.

2 Likes

You can find a tool in the view section called “find all” or something like that. You can basically search a term to find that term in all scripts. Try searching for :Destroy(),.Parent =, etc.

It also might be possible when the camera psrts are unanchored

1 Like

Ok, I see my issue now, the problem is that the parts in workspace do not load until the player’s character loads, I will have to clone everything into the workspace, thank you for your assistance.

2 Likes

I think it could be because of the “StreamingEnabled” property in workspace

4 Likes

Thank you so much, thank you!!! Disabling that property fixed everything, now my starter camera works perfectly fine and smooth with the camera thingy!!!

1 Like

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