Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Code erroring when trying to locate object at the object's location?

Asked by 4 years ago
Edited by JesseSong 3 years ago

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)

0
Try printing all the children of the workspace, use :GetChildren() and then itterate through that table. See what it outputs. Benbebop 1049 — 4y
0
I've already tried that before, and I've tested in studio. The object is still there, yet it can't find it! I honestly don't know why this is happening MacauleyP_Plays 15 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

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.

0
hmm, I'll try if that fixes the problem! MacauleyP_Plays 15 — 4y
0
That just seemed to stop the code working at all, I'll try using a wait() instead MacauleyP_Plays 15 — 4y
0
I'm also not great at scripting, how do I use the :WaitForChild? Would I use it in the line where I assign it to a local variable? or use it before assigning it? MacauleyP_Plays 15 — 4y
0
Still getting the following error: TrainsSpawned is not a valid member of Folder "Workspace.DepotsAndTrains.FranklintonMetroDepot.DStockTrains" coming from the line of code here: script.Parent.Parent.Parent.TrainsSpawned = (TrainsSpawnedobj + 1) MacauleyP_Plays 15 — 4y
View all comments (4 more)
0
Where is your script located, and what type of script are you using? VikkiVuk 74 — 4y
0
The script is located in a folder, which is a child of a folder, which is a child of a folder, which is a child of workspace. MacauleyP_Plays 15 — 4y
0
What type of script is it? VikkiVuk 74 — 4y
0
its a normal script (not a local script) MacauleyP_Plays 15 — 4y
Ad
Log in to vote
0
Answered by
Dec_ade 47
3 years ago
Edited 3 years ago

"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")
0
Why would this be the problem though when the error is that it isn't a child of workspace? MacauleyP_Plays 15 — 3y

Answer this question