Attempt to index nil with GetChildren()

Hello Developers,

I was wondering if anybody could help me with a project I’m trying to complete at the moment. I’m using :GetChildren() but am getting an error I’ve not really come across before. It’s been a while since I’ve programmed using this method and can’t work out why I’m getting this error!

Any help would be appreciated. :heart:

local ProductsFolder = game.ServerStorage:WaitForChild("UIProducts", 5)
local Products = ProductsFolder:GetChildren()

image
image

LocalScript cannot access ServerStorage. Simple.

Adding on to @Quwanterz, if you want to “access” ServerStorage from localscripts, you can use remotes to go to a server script.
Server scripts can access ServerStorage (Hence the name, you know?)

Actually, you can just put the folder in ReplicatedStorage instead of ServerStorage. LocalScripts CAN access RS.

Local Scripts cannot access server storage.

What you can do is create a remote event that will power the serverstorage, and callback all children to the localscript.

Example Code:

Local Script:

game.ReplicatedStorage.RemoteEvent:FireServer()

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(Products)
-- function
end)

Server Script:

local ProductsFolder = game.ServerStorage:WaitForChild("UIProducts", 5)

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr)
local Products = ProductsFolder:GetChildren()
game.ReplicatedStorage.RemoteEvent:FireAllClients(Products)
-- or if you want it to be that one player, do game.ReplicatedStorage.RemoteEvent:FireClient(plr, Products)
end)

Hope this helps.

I’m so stupid! I haven’t coded for a while because of exams. Thank you everyone for your help.

1 Like

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