I am making a trail shop for my game with an inventory. When you buy the trail, it adds it to a table with all the other trails you own. The table is then represented in the inventory frame where you can then equip the trails. This is what is supposed to look like:
I know there are frames in the scrolling frame and I know the item frames’ visibility is set to true. The problem is, they are not visible in the scrolling frame when you play the game but are visibile if you just put the frame into the scrolling frame with roblox studio explorer. This means that it has something to do with the script. This is a local script that updates the inventory:
local shopFrame = game.StarterGui.Shop:WaitForChild("Frame")
local itemScroller = script.Parent
local itemPreview = script.Parent.Parent.ItemPreview
local trailsFolder = game.ReplicatedStorage:WaitForChild("Trails")
local ownedTrailsFolder = game.Players.LocalPlayer:WaitForChild("OwnedTrails")
local shopFrame = script.Parent.Parent
local invFrame = game.StarterGui:WaitForChild("Inventory")
local player = game:GetService("Players").LocalPlayer
shopFrame.Visible = false
itemPreview.Visible = false
local itemsFolder = game.ReplicatedStorage:WaitForChild("Trails")
function updateInventory()
for i, child in pairs(invFrame.ScrollingFrame:GetChildren()) do
if child:IsA("Frame") then child:Destroy() end
end
local ownedTrails = ownedTrailsFolder:GetChildren()
print(ownedTrails)
table.sort(ownedTrails, function(a, b)
return trailsFolder[a.Name].Price.Value < trailsFolder[b.Name].Price.Value or trailsFolder[a.Name].Price.Value == trailsFolder[b.Name].Price.Value and a.Name < b.Name
end)
for i, trail in pairs(ownedTrails) do
local item = script.Item:Clone()
item.SelectButton.Text = "EQUIP"
item.Title.Text = trail.Name
item.Parent = invFrame.ScrollingFrame
item.SelectButton.MouseButton1Click:Connect(function()
game.ReplicatedStorage.TrailSelectedRE:FireServer(false, trail)
for i, itemButton in pairs(item.Parent:GetChildren()) do
if itemButton:IsA("ImageLabel") then
itemButton.SelectButton.Text = "EQUIP"
item.SelectButton.Text = "EQUIPPED"
end
end
end)
end
end
updateShop()
updateInventory()
ownedTrailsFolder.ChildAdded:Connect(function()
updateInventory()
end)
ownedTrailsFolder.ChildRemoved:Connect(function()
updateInventory()
end)
What is wrong with my script that is causing the duplicated item frame to not be visible?
Note: If I did not explain it well or you need more of an explanation, just ask.
If you send a copy of the UI from in-game we could debug it. There are a lot of things that might be happening (incorrect parent, visible property, transpareny, zindex, etc).
So then you can make changes with it an see what the problem is. There is something wrong with your format, so you’ll probably just need to trouble shoot it. If you copy it and send it to me I can probably fix it in a few mins (UI is client sided anyways).
Im pretty sure if the zindex is the same as the scroll fram then you should make it higher. For example, scroll frame zindex is 1 and then make the clone zindex 2
The problem is that your variable is getting the frames from game.StarterGui. This will not work since the StarterGui is only the template of the Guis that will be duplicated to all the players while the PlayerGui is the Gui of the player’s screen.
Change all of your variables into this:
local player = game:GetService("Players").LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local shopFrame = playerGui:WaitForChild("Shop"):WaitForChild("Frame")
local itemScroller = script.Parent
local itemPreview = script.Parent.Parent.ItemPreview
local trailsFolder = game.ReplicatedStorage:WaitForChild("Trails")
local ownedTrailsFolder = player:WaitForChild("OwnedTrails")
local shopFrame = script.Parent.Parent
local invFrame = playerGui:WaitForChild("Inventory")
Also change the line for i, trail in pairs(ownedTrails) do
and replace the pairs into ipairs
ipairs loops through the table in order (since you sorted the table), while pairs loops randomly
Also can you show the location of your script so I can clean the variables to make sure there will be no errors printed (since the script could load before the PlayerGui exists which will result in an error)