The Problem
I am working on a basic 2D based game and the script is sometimes not going into 2D instead it stays on 3D.
And when you die the camera will be focusing on nothing and not the character.
If Instance:FindFirstChild cannot find a child with a given name, it returns nil. So the issue seems to be, it was not loaded when :FindFirstChild was called.
You can use :WaitForChild to wait for a child.
local rootPart = character:WaitForChild("HumanoidRootPart")
Also, repeat wait() until player.Character?
Don’t reinvent the wheel, player.CharacterAdded exists, and you can :Wait() for it to fire.
local character = player.Character or player.CharacterAdded:Wait() -- obliterate that loop u had pls
Basically, if the character is loaded already, character is assigned to player.Character, if not, that means it’s nil and isn’t loaded yet, so :Wait() for player.CharacterAdded to fire.