Change camera on player spawning

Currently I am trying to set the players camera system to a custom one as soon as they join. I tried just enabling it through a loop but it gives me this error

attempt to index boolean with 'Position'

After that the camera does change, but I want to find a way in which I check for the spawn of the player and only after that I change their camera

I’ve looked around the forum quite a lot and read through the player events. Although for me it seems correct, the script just doesn’t seem to work.

	local character = player.CharacterAdded:Connect(function(character)
			local rootPart = character:WaitForChild("HumanoidRootPart",0.2)	
		until rootPart ~= nil
		--change camera

Also after some troubleshooting (inserting prints to output in different parts of the function) I’ve come to the conclusion that the PlayerAdded event doesn’t fire.

The code that would be most relevant here has been removed so can’t really offer you any strong advice on your code explicitly, just the abstract problem that’s present.

I’m not particularly sure what the point of the repeat loop is. WaitForChild already yields until a child with the name given in the strings is found, so you can just remove the repeat loop and the timeout of 0.2 seconds as well. Avoid loops if there’s a better solution available.

As for your conclusion, whether that’s correct or not and part of the actual reason why your code doesn’t work, you can solve that by using boilerplate to account for players that join before PlayerAdded connects. Beyond that, if using said boilerplate doesn’t help resolve the issue then you need to supply more information or code.

local Players = game:GetService("Players")

local function playerAdded(player)

for _, player in ipairs(Players:GetPlayers()) do
1 Like

What I am using for the camera system is this module script here

Basically inside this module script all the values for the custom camera are already defined and there’s a function to Enable and Disable the camera mode. It works when tied to a button, so I don’t think the module script is the problem.

Here’s the outcome when I just use the Enable function

And here’s the error it throws, although the camera did change.

RunService:fireRenderStepEarlyFunctions unexpected error while invoking callback: ReplicatedStorage.OTS Camera System:232: attempt to index boolean with 'Position'

I removed the repeat loop and time value in WaitForChild and am currently looking into some sort of system to detect player spawning.

I have found a solution, and it’s way simpler than I thought it would be. Here’s the code: