✓ Accepted answer
The reason its failing is if you string a bunch of objects into what Roblox calls a GetFullName() (EG: "game.workspace.part.script"). Unless all the parts are there already on script run then things would load normally and not error out.
But if something loads slower than the script or fails to load by the time your script has got to the part where you require the object it will fail and return nil as you know.
So to try and keep things happy i would make sure each object exists before continuing, so I've made up 2 ways on how to accomplish this. There are many ways on doing this and some a much neater than these ways, but the two ways should suffice to your needs.
The number 2 way, also saves the objects in a value for you to use later on Via CameraBase and DevTrooperSP
Try these ways:
local CamPartLoaded = false
repeat
local Group = game.Workspace:FindFirstChild("MorphGui")
if(Group == nil) then error("MorphGui is nil and not a valid member of workspace!!") end
CamPartLoaded = Group:FindFirstChild("CamPart") ~= nil
wait()
until CamPartLoaded == true
local DevTroopSpotLoaded = false
repeat
local Group = game.Workspace:FindFirstChild("MorphGui")
if(Group == nil) then error("MorphGui is nil and not a valid member of workspace!!") end
DevTroopSpotLoaded = Group:FindFirstChild("DevTrooperSpot") ~= nil
wait()
until DevTroopSpotLoaded
local Group = game.Workspace:FindFirstChild("MorphGui")
if(Group == nil) then error("MorphGui is nil and not a valid member of workspace!!") end
local CameraBase = Group:WaitforChild("CamPart",30)
local DevTrooperSP = Group:WaitforChild("DevTrooperSpot",30)
There are many ways to wait for something to load on game run or even while the game is running.
If you require the script in question to always run thus always search for the object(s) during playtime then i would use no "1)" way.
Hope this helps!
Edit: typos and stuff :p
1 comment
You can use game:Loaded() and then maybe use a global variable like _G if your script is somewhere else