Virvek
(Virvek)
July 17, 2021, 4:01am
1
I hate to ask this, it’s such a simple problem, yet I can’t seem to find the solution to. The for loop goes through all the children in the folder. However, it’s not looping… for some reason the script decides to skip the for loop. I’ve used the print method, yet nothing…
for i,v in pairs(game.Workspace.Boats:GetChildren()) do
if v == nil then
-- nothing
else
end
end
D0RYU
(nici)
July 17, 2021, 4:03am
2
I don’t think v will ever be nil if it is an instance, so I see no point in that if statement
also does the instance “Boats” have children?
1 Like
Virvek
(Virvek)
July 17, 2021, 4:04am
3
If the server is new and/or no one has boats, the folder will return empty.
D0RYU
(nici)
July 17, 2021, 4:06am
4
if it returns empty then that means it won’t run at all
still no need for the if statement
someone correct me if I am wrong but I don’t think v can be nil using :GetChildren()
2 Likes
bbro1666
(Demoted)
July 17, 2021, 4:06am
5
try printing the number of children before the loop runs and see if its detecting any children in the first place
1 Like
Virvek
(Virvek)
July 17, 2021, 4:08am
6
So you’re correct. It will only run if there are children inside the folder. Currently making a work around.
That should be correct.
Only children which are non-nil should be part of the table returned by GetChildren().
I would consider the possibility of the script execution not reaching that point. Common culprits are while true() do loops above the block.
1 Like
Virvek
(Virvek)
July 17, 2021, 4:15am
8
Yeah, I made the simple work around:
local Check = game.Workspace.Boats:FindFirstChild("Boat")
if Check == nil then
-- there are no boats
end
bbro1666
(Demoted)
July 17, 2021, 4:21am
9
Instead of making 2 different objects I would do
local boats = workspace.Boats:GetChildren()
if #boats == 0 then
--no boats were found
end
1 Like