Script cant find object in workspace

Hello, ive made an npc walking ai but it doesnt seem to work and its breaks on this line below for some reason

for i, waypoint in pairs(workspace.Waypoints:GetChildren()) do

ive done some testing and found out that the script doesnt know what workspace.Waypoint is and its returning 0 on this line below

print(#workspace.Waypoints:GetChildren())

Could you show explorer, please?

Hi, what’s the error? Do you have a folder in workspace called Waypoints? If yes, is there anything inside the folder Waypoints?

heres the explorer (its a server script btw)
image

Why not try workspace:WaitForChild(“Waypoints”)?

now it prints out 5 on the first time but if i run it again it just prints 0 again

WaitForChild is mostly never really necessary for server scripts.

nvm it got back to printing 0 again

Check if they’re anchored, or check if they disappear in explorer while running it. Might be falling into the void.
It’s hard to tell whats going on without the full script.

theire there and anchored and i also tried the same with a module script before and got the exact same result

Print out the table and show output please

local points = workspace:WaitForChild("Waypoints")
for i, waypoint in pairs(points:GetChildren()) do

for some reason this time it worked thanks

Its because assets in the game haven’t loaded yet, that’s why you need to use :WaitForChild(), it waits for the item to load before continuing from its current point.

This line gave away what the problems was … like TomPlays63 said.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.