#What's the correct way to make this work?
1 messages · Page 1 of 1 (latest)
local gs1 = workspace:WaitForChild("Map"):WaitForChild("GasStation1")
local store = gs1:WaitForChild("Store")
local interior = store:WaitForChild("Interier")
local register = interior:WaitForChild("Register"):WaitForChild("CashRegister")
local drawer = register:WaitForChild("CashDrawer")
local drawerprompt = drawer:WaitForChild("ProximityPrompt")
local itemsFolder = interior:WaitForChild("Items")
local maxStock = 8
for _, itemModel in ipairs(itemsFolder:GetChildren()) do
local children = itemModel:GetChildren()
for i = maxStock + 1, #children do
children[i]:Destroy()
end
end```
wdym
local gs1 = workspace:WaitForChild("Map"):WaitForChild("GasStation1")
local store = gs1:WaitForChild("Store")
local interior = store:WaitForChild("Interier")
local register = interior:WaitForChild("Register"):WaitForChild("CashRegister")
local drawer = register:WaitForChild("CashDrawer")
local drawerPrompt = drawer:WaitForChild("ProximityPrompt")
local itemsFolder = interior:WaitForChild("Items")
local maxStock = 8
for _, itemModel in ipairs(itemsFolder:GetChildren()) do
local parts = {}
for _, child in ipairs(itemModel:GetChildren()) do
if child:IsA("BasePart") then
table.insert(parts, child)
end
end
if #parts > maxStock then
table.sort(parts, function(a, b)
return a.Name < b.Name
end)
for i = maxStock + 1, #parts do
parts[i]:Destroy()
end
end
end
thanks
first of all
do not use that many WaitForChild
thats useless
just use points
cause most of the things that spawns in the game they spawn before any script
so no need to use that many wait for child
WaitForChild() is misused all the time, and I'm guilty of it too. Hopefully, this video will shed some light on when and when NOT to use WaitForChild()!
Have you ever wanted to learn Roblox Studio and Roblox Scripting? Check out my course: https://bit.ly/LuaScriptingCourse
Use code DEVELOPER for 33% off!
My linktree:
https://linktr.ee/crusherf...
watch this
got it
Only use waitforchild if something isint loaded yet right?
yea
for i, obj in itemModel:GetChildren() do
if i <= maxStock then
obj:Destroy()
end
end
** You are now Level 1! **
But I assume this is for a “drawer” or “cash register” type thing