Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I create a designated frame for every object in a players folder?

Asked by 3 years ago
Edited 3 years ago

Ok so essentially I have a folder inside of a player that is their inventory its a custom folder not the roblox default one. I have to get the children in the folder then create a frame for each one but how can I do that. Also I each frame has a value called "WeaponName" so that they can get seperated from other frames. No fancy positioning or anything required as it is already in a uilistlayout in a larger scrolling frame.

I have this script right now and in my mind it works but for some reason it doesnt in game. I go into server mode and put a part in the players inventory folder however it does not clone the frame and change the frames parent why?

Its a local script inside of the scrollingframe:

while true do
wait(1)
local player = game.Players.LocalPlayer

local children = player.Inventory:GetChildren()
print(#children)
for i, child in ipairs(children) do
    local weaponframe = script.Parent.Parent.Frame:Clone()
    weaponframe.Parent = script.Parent
    weaponframe.WeaponName.Value = children:GetChildren()[1].Name
    end
    endeaponframe.WeaponName = child[1].Name
end

1 answer

Log in to vote
1
Answered by 3 years ago

This is because Instance:GetChildren() only looks at an instance's children once, that is when this function is run. Not after, and not before. It doesn't look at children being added, and doesn't look at them being removed - your script is running as intended.

You need to use Instance.ChildAdded and Instance.ChildRemoved in your script. So your script should look like this:

for _,child in pairs(inventory:GetChildren()) do
    -- add inventory frame
end
inventory.ChildAdded:Connect(function(child)
    -- add inventory frame
end)
inventory.ChildRemoved:Connect(function(child)
    -- remove inventory frame
end)
Ad

Answer this question