Hello, I’ve been experimenting with scripting these days and today I came across one error that’s triggering me.
wait(1)
local setting = require(game.ServerScriptService.Kiosk)
local kioskfolder = game.ServerStorage:FindFirstChild(setting.Name)
local category = kioskfolder:FindFirstChild(script.Parent.Name)
for _, v in ipairs(category:GetChildren()) do
local clone = script.Parent.Template:Clone()
clone.Parent = script.Parent
clone.Visible = true
clone.ItemName.Text = v.Name
clone.Name = v.Name
end
The script is supposed to get all children from a folder inside of another folder although it doesn’t seem to work the way I tried to do it.
You are getting things too early, you must wait before getting them because they haven’t loaded yet!
local ServerScriptService = game:GetService("ServerScriptService")
local ServerStorage = game:GetService("ServerStorage")
-- Always yield when requiring modules
local setting = require(ServerScriptService:WaitForChild("Kiosk"))
-- This folder might have not loaded yet, you could check if so just by printing this variable
local kioskfolder = ServerStorage:WaitForChild(setting.Name)
local category = kioskfolder:WaitForChild(script.Parent.Name)
for _, v in ipairs(category:GetChildren()) do
local clone = script.Parent.Template:Clone()
clone.Parent = script.Parent
clone.Visible = true
clone.ItemName.Text = v.Name
clone.Name = v.Name
end
Have you checked that you placed the “setting” module script in the right place? Btw I recommend placing module scripts in the server storage instead of the server script service
You didn’t name the module script correctly, and there might be a space at the end of the name. Also, you don’t need to use WaitForChild on the server unless you’re dealing with someone’s character just getting added into the game.
Why then, the setting variable which holds the required module is named “setting” but the module is named “Kiosk”? (I think you mismatched the names which is the problem)
local setting = require(ServerScriptService:WaitForChild("setting"))
If it’s a Local Script then add the kiosfolder inside ReplicatedStorage instead and Change the code to this (Also parent the Kisok module to ReplicatedStorage).
wait(1)
local setting = require(game.ReplicatedStorage.Kiosk)
local kioskfolder = game.ReplicatedStorage:FindFirstChild(setting.Name)
local category = kioskfolder:FindFirstChild(script.Parent.Name)
for _, v in ipairs(category:GetChildren()) do
local clone = script.Parent.Template:Clone()
clone.Parent = script.Parent
clone.Visible = true
clone.ItemName.Text = v.Name
clone.Name = v.Name
end