Need help Updating GUI with items in folder

I Need help with a shop script. I used a version of the shop template from AlvinBlox as a base, but I’m having a few problems with the shop tools not being transferred over to my inventory. The items are being place in the proper folders but not showing up in the inventory GUI. I’m running a for loop to get all the items in the folder, but I’ve noticed that if the items are in the folder before playing the game they will show up as i need them to, but if I play the game and then buy the items, they are added to the folder but don’t show up in gui. I’ve been trying for days on something that may take someone ten minutes. but I can’t move forward until I get this fixed, any help will be appreciated.

(Weapons Folder Empty)
folder

(Weapons Folder After Buying Items From Shop)
folder 2

(Video)
robloxapp-20220409-1411458.wmv (1.3 MB)

(Shop Script)

local gui = game.Players.LocalPlayer.PlayerGui

-- Inserts a template for every item in the Tools folder
local folder = game.ReplicatedStorage:WaitForChild("ShopItems")
local frame = gui.LobbyScreenGUI.StoreFrame.ShopFrame.ShopButton:WaitForChild("StoreFrontFrame")
local template = frame:WaitForChild("ShopScrollingFrame"):WaitForChild("ShopSlot")
local slot = gui.LobbyScreenGUI.InteractFrame.InventoryButton.InventoryFrame:FindFirstChild("WeaponsScrollingFrame"):FindFirstChild("WeaponsSlot"):WaitForChild("Title")

local weaponFolder = game.ReplicatedStorage.Weapons
local vehicalsFolder = game.ReplicatedStorage.Vehicals
local emoteFolder = game.ReplicatedStorage.Emotes
local miscellaneousFolder = game.ReplicatedStorage.Miscellaneous
local clothingFolder = game.ReplicatedStorage.Clothing

for _, item in pairs(folder:GetChildren()) do
	
	local newTemplate = template:Clone()
	
	newTemplate.Price.Text = "$"..item:WaitForChild("Cost").Value
	newTemplate.Visible = true
	newTemplate.Image =  item.TextureId
	--newTemplate.Price.Text = item.Name
	newTemplate.Parent = frame.ShopScrollingFrame
	slot.Text = "Equip"
	
newTemplate.Price.MouseButton1Click:Connect(function()
		
	if game.Players.LocalPlayer.leaderstats.Money.Value >= item:WaitForChild("Cost").Value then
		game.Players.LocalPlayer.leaderstats.Money.Value = game.Players.LocalPlayer.leaderstats.Money.Value - item:WaitForChild("Cost").Value

		newTemplate.Price.Text = "Purchased"
		newTemplate.Price.BackgroundColor = BrickColor.new("Bright green")
		item:WaitForChild("Cost").Value = 0
			
		if item:WaitForChild("ItemType").Value == "Clothing" then
				
			local newTool = item:Clone()
			newTool.Parent = miscellaneousFolder
				
		elseif item:WaitForChild("ItemType").Value == "Weapons" then
				
			local newTool = item:Clone()
			newTool.Parent = weaponFolder
				
		elseif item:WaitForChild("ItemType").Value == "Vehicals" then
				
			local newTool = item:Clone()
			newTool.Parent = vehicalsFolder
				
		elseif item:WaitForChild("ItemType").Value == "Emotes" then
				
			local newTool = item:Clone()
			newTool.Parent = emoteFolder
				
		elseif item:WaitForChild("ItemType").Value == "Miscellaneous" then
				
			local newTool = item:Clone()
			newTool.Parent = miscellaneousFolder
	
		end
		
		local newTool = item:Clone()
		newTool.Parent = game.Players.LocalPlayer.Backpack
			
		game.Players.LocalPlayer.leaderstats.Purchases.Value = 1

		script.Parent.Parent.Availble.Visible = true
		wait(1)
		script.Parent.Parent.Availble.Visible = false	
	else
		newTemplate.Price.Text = "Purchase Failed"
		newTemplate.Price.BackgroundColor = BrickColor.new("Really red")
		wait(2)
		newTemplate.Price.Text = "$"..item:WaitForChild("Cost").Value
		newTemplate.Price.BackgroundColor = BrickColor.new("White")
		newTemplate.Price.BackgroundTransparency = 0.5
	end
end)
end

(Weapons Script)

local folder = game.ReplicatedStorage:WaitForChild("Weapons")
local frame = gui.LobbyScreenGUI.InteractFrame.InventoryButton:WaitForChild("InventoryFrame")
local template = frame:WaitForChild("WeaponsScrollingFrame"):WaitForChild("WeaponsSlot")

for _, item in pairs(folder:GetChildren()) do

	local newTemplate = template:Clone()
	
	newTemplate.Visible = true
	newTemplate.Image =  item.TextureId
	newTemplate.Parent = frame.WeaponsScrollingFrame
	newTemplate.Title.Visible = true
	newTemplate.Title.Text = "Equip"
end
1 Like

Do you mind sharing the place file, it would be easier for me to find the issue.

You can do it in DMs too.

Final script:

local gui = game.Players.LocalPlayer.PlayerGui

-- Inserts a template for every item in the Tools folder
local folder = game.ReplicatedStorage:WaitForChild("ShopItems")
local frame = gui.LobbyScreenGUI.StoreFrame.ShopFrame.ShopButton:WaitForChild("StoreFrontFrame")
local template = frame:WaitForChild("ShopScrollingFrame"):WaitForChild("ShopSlot")

local interactFrame = script.Parent.Parent.Parent.Parent:WaitForChild("InteractFrame")
local inventoryButton = interactFrame.InventoryButton
local inventoryFrame = inventoryButton.InventoryFrame
local weaponScrollingFrame = inventoryFrame.WeaponsScrollingFrame

local weaponFolder = game.ReplicatedStorage.Weapons
local vehicalsFolder = game.ReplicatedStorage.Vehicals
local emoteFolder = game.ReplicatedStorage.Emotes
local miscellaneousFolder = game.ReplicatedStorage.Miscellaneous
local clothingFolder = game.ReplicatedStorage.Clothing

spawn(function()
	game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
	task.wait(1)
end)	


for _, item in pairs(folder:GetChildren()) do
	
	local newTemplate = template:Clone()
	
	newTemplate.Price.Text = "$"..item:WaitForChild("Cost").Value
	newTemplate.Visible = true
	newTemplate.Image =  item.TextureId
	--newTemplate.Price.Text = item.Name
	newTemplate.Parent = frame.ShopScrollingFrame
	
	--[[local object = item:Clone()
	object.Parent = newTemplate.ViewportFrame

	local camera = Instance.new("Camera")
	camera.CFrame = CFrame.new(object.Handle.Position + (object.Handle.CFrame.lookVector*5)+Vector3.new(2,2,2),object.Handle.Position)
	camera.Parent = newTemplate.ViewportFrame

	newTemplate.ViewportFrame.CurrentCamera = camera]]

newTemplate.Price.MouseButton1Click:Connect(function()
		
	if game.Players.LocalPlayer.leaderstats.Money.Value >= item:WaitForChild("Cost").Value then
		game.Players.LocalPlayer.leaderstats.Money.Value = game.Players.LocalPlayer.leaderstats.Money.Value - item:WaitForChild("Cost").Value

		newTemplate.Price.Text = "Purchased"
		newTemplate.Price.BackgroundColor = BrickColor.new("Bright green")
		item:WaitForChild("Cost").Value = 0
			
		if item:WaitForChild("ItemType").Value == "Clothing" then
				
			local newTool = item:Clone()
			newTool.Parent = miscellaneousFolder
				
		elseif item:WaitForChild("ItemType").Value == "Weapons" then
				
			local newTool = item:Clone()
			newTool.Parent = weaponFolder
				
		elseif item:WaitForChild("ItemType").Value == "Vehicals" then
				
			local newTool = item:Clone()
			newTool.Parent = vehicalsFolder
				
		elseif item:WaitForChild("ItemType").Value == "Emotes" then
				
			local newTool = item:Clone()
			newTool.Parent = emoteFolder
				
		elseif item:WaitForChild("ItemType").Value == "Miscellaneous" then
				
			local newTool = item:Clone()
			newTool.Parent = miscellaneousFolder
	
		end
		
		local newTool = item:Clone()
		newTool.Parent = game.Players.LocalPlayer.Backpack
		newTemplate:Clone().Parent = weaponScrollingFrame
			
		game.Players.LocalPlayer.leaderstats.Purchases.Value = 1

		script.Parent.Parent.Availble.Visible = true
		wait(1)
		script.Parent.Parent.Availble.Visible = false	
	else
		newTemplate.Price.Text = "Purchase Failed"
		newTemplate.Price.BackgroundColor = BrickColor.new("Really red")
		wait(2)
		newTemplate.Price.Text = "$"..item:WaitForChild("Cost").Value
		newTemplate.Price.BackgroundColor = BrickColor.new("White")
		newTemplate.Price.BackgroundTransparency = 0.5
	end
end)
end
2 Likes

I replayed with my Discord link but its waiting approval, maybe send me your and i’ll send you the rbxl in DM

2 Likes

it was a good attempt, but I think it has more to do with the Weapon Script then the Shop Script because it’s just cloning the shop item to the weaponscrollingframe after purchased. I want it to get the clone from the assigned folder not the shop, the shop items are assigned by a string value. The for loop will get the children from the folder and then show them in the assigned scrollingframe.

1 Like