I'm trying to make a for loop that checks each item in server storage.
This is what I've tries so far.
for i in serverstorage do if i.Starter then local item = i:clone() i.Parent = player.PlayerGui end end
local serverstorage = game:GetService("ServerStorage") -- Gets the ServerStorage for i, child in pairs(serverstorage:GetChildren()) do -- Creates a table of the children in serverstorage if child:FindFirstChild("Starter") then -- Using FindFirstChild stops the annoying error local item = child:Clone() item.Parent = player.PlayerGui end end
Edit: Thanks to incapazz for pointing out that you likely are using a local script. In that case just change ServerStorage
to ReplicatedStorage
. If not, then ServerStorage is fine.
Since you’re using PlayerGui, I’m assuming this is a local script. ServerStorage doesn’t exist on the client. Instead use ReplicatedStorage and it’s :Clone not :clone.
for_, v in pairs(game:GetService('ReplicatedStorage'):GetChildren()) do if v:FindFirstChild'Starter' then local item = v:Clone() -- Clone not clone item.Parent = player:WaitForChild"PlayerGui" end end