So, I've been making a script that requires an integer value to put into a spawned object (to know which it is, reason not important to problem) , but it keeps giving me errors that the object does not exist. I've had this problem for months, I've asked around but no one is able to help because it makes no sense! The integer object the script tries to locate exists in the same place at all times, its parent never changes, nor its name, yet the script still errors saying it doesn't exist there. The error message is as follows: Depots_and_trains is not a valid member of Workspace "Workspace"
Depots_and_trains is a folder in the workspace. Why can't it find it? Its RIGHT THERE!!!
I've also had similar problems where it cannot find other objects, despite it existing there. I've tried finding it from game.workspace.(location) and script.parent(and so on...) but neither works, both giving errors that it cannot be found where it LITERALLY EXISTS!!! I would really appreciate any help! Please feel free to ask questions!
Below is the line of code that gives the error:
local NAobj = game.Workspace.Depots_and_trains.Franklinton_MainLine_Depot.Class37_Trains.NextAddress.Value
Edit: Seems to be that it thinks Workspace is a folder? TrainsSpawned is not a valid member of Folder "Workspace.DepotsAndTrains.FranklintonMetroDepot.DStockTrains" (Different code, but similar error originating from the same code)
What could be happening is the script is running before the game has loaded, so try writing game.Loaded:Wait()
before the variable declaration, or use :WaitForChild
.
"DStockTrains" is a folder. Maybe DStockTrains has not loaded all of its children. What you could do is :
local DepotsAndTrains = workspace:WaitForChild("DepotsAndTrains") local FranklintonMetroDepot = DepotsAndTrains:WaitForChild("FranklintonMetroDepot") local DStockTrains = FranklintonMetroDepot:WaitForChild("DStockTrains") local TrainsSpawned = DStockTrains:WaitForChild("TrainsSpawned")