Problem with cloning image button

  1. What do I want to achieve? I want to clone an image button as how many times as the tools in a folder.

  2. What is the issue? It is not printing anything. And it is not showing anything

  3. What solutions have you tried so far? I have looked into devhub and still cant find a solution.

Keep in mind im a beginner to this cloning stuff and all and watched this tutorial on the topic: [SHOP] How to make a SIMULATOR game in ROBLOX Part 4! - YouTube

for i , item in next , game.ReplicatedStorage.Shared:FindFirstChild("Tools"):GetChildren() do
	if item:IsA("Tool") then
		local price = item:FindFirstChild("Cost")
		local img = item:FindFirstChild("ImgId")
		local order = item:FindFirstChild("order")
		if price and img and order then
			if order.Value == i then
				print(item.Name)
				local temp = script.Parent.tools_gui.tools_frame.ScrollingFrame.temp:Clone()
				temp.Parent = script.Parent.tools_gui.tools_frame.ScrollingFrame
				temp.Name = item.Name
				local priceval = Instance.new("StringValue")
				priceval.Value = price.Value
				priceval.Parent = temp
				
				temp.Visible = true
			else
				continue
			end
			
		end
	end
end

local RS = game:GetService("ReplicatedStorage")
local Shared = RS:WaitForChild("Shared")
local ToolFolder = Shared:WaitForChild("Tools")
local Tools = ToolFolder:GetChildren()
local parent = script.Parent
local toolsGui = parent:WaitForChild("tools_gui")
local toolsFrame = toolsGui:WaitForChild("tools_frame")
local scrollingFrame = toolsFrame:WaitForChild("ScrollingFrame")
local temp = scrollingFrame:WaitForChild("temp")

for i, item in ipairs(Tools) do
	if item:IsA("Tool") then
		local price = item:FindFirstChild("Cost")
		local img = item:FindFirstChild("ImgId")
		local order = item:FindFirstChild("order")
		if price and img and order then
			if order.Value == i then --ill leave this here but order value should match index since the ipairs iterator is being used
				print(item.Name)
				local temp = temp:Clone()
				temp.Parent = scrollingFrame
				temp.Name = item.Name
				local priceval = Instance.new("StringValue")
				priceval.Value = price.Value
				priceval.Parent = temp
				temp.Visible = true
			else
				continue --you can possible remove this else continue bit
			end
		end
	end
end

Alternate version (more likely to work as intended).

local RS = game:GetService("ReplicatedStorage")
local Shared = RS:WaitForChild("Shared")
local ToolFolder = Shared:WaitForChild("Tools")
local Tools = ToolFolder:GetChildren()
local parent = script.Parent
local toolsGui = parent:WaitForChild("tools_gui")
local toolsFrame = toolsGui:WaitForChild("tools_frame")
local scrollingFrame = toolsFrame:WaitForChild("ScrollingFrame")
local temp = scrollingFrame:WaitForChild("temp")

for i, item in ipairs(Tools) do
	if item:IsA("Tool") then
		local price = item:FindFirstChild("Cost")
		local img = item:FindFirstChild("ImgId")
		local order = item:FindFirstChild("order")
		if price and img and order then
			print(item.Name)
			local temp = temp:Clone()
			temp.Parent = scrollingFrame
			temp.Name = item.Name
			local priceval = Instance.new("StringValue")
			priceval.Value = price.Value
			priceval.Parent = temp
			temp.Visible = true
		end
	end
end
1 Like

Thank you for your help. But it doesn’t work. Is there anything i did wrong?

An error in console would be helpful, I’m assuming one or more of the original references are incorrect.

i dont have any errors or warnings in my output.

This is i sent u if this helps.

From your script.

local price = item:FindFirstChild("Cost")
local img = item:FindFirstChild("ImgId")
local order = item:FindFirstChild("order")

What they should be according to how they appear in explorer.

local price = item:FindFirstChild("Price")
local img = item:FindFirstChild("ImgID")
local order = item:FindFirstChild("order")

It might be worth checking the other references too to make sure everything matches.

1 Like

Would the scrolling frame need a UIGridLayout to show the image?