item:Clone not visible

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:


Instead, when you play the game, it looks like this:

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.

1 Like

You aren’t positioning the clone, causing them to overlap behind each other. Perhaps you may want to use a UIListLayout?

Forgot to mention that, I am:

image


It is right there as shown by the outline, but it is clearly not visible at all

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).

Are you making these two frames visible again?

shopFrame.Visible = false
itemPreview.Visible = false

Is the .Visible property set to true? Also are you sure the background isn’t in front of the frames?

What do you mean by visible again?

I made the parent equal to the inventory gui, not the scrolling frame and you still cannot see it:

Also here are the properties for one of the item frames:

I meant GuiObject.Visible. The problem could be that one of the parents of the UI has Visible set to false.

https://developer.roblox.com/en-us/api-reference/property/GuiObject/Visible



All its parents’ visibility is true.

1 Like

Yeah, there are a lot of thing that could be causing this.

What I’d recommend is:

  • Running the game
  • Copying the UI from PlayerGui
  • End the game
  • Paste the UI into StarterGui
  • Mess around with the UI in StarerGui until you find what’s causing the problem.

It can be a lot of things:

Also clips descendants and DisplayOrder :+1:

Im confused why I would copy it from the playerGUI since it is not working there.

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).

So here is what I found. If you are just messing with it in studio, not testing, and place the template in the scrolling frame then it is visible.


But if you load into the game and try, the templates are not visible at all.

1 Like

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

1 Like

It seems that the name of the ScrollingFrame is ScrollingFrame
image

but the property of one of the frame’s Parent is named Inventory

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

3 Likes

I made the template’s zindex 2 and the scroll frame 2 but it did not work.

scroll frame should be set to 1 zindex

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)

Sorry, I misstyped. Meant to say it is zindex 1

1 Like