Help Making an Inventory and Shop GUI!

Good Night!
I’m working on a store for my Roblox game, but I’m having problems.

WHAT I WANT TO ACHIEVE:
Basically, what I want to do is that when the player buys an item in the store, the item in the store moves to an inventory, I’m doing this by moving the parent of the textbutton of the item that the players would buy.

WHAT IS THE PROBLEM:
Well, the problem is that when the player makes the purchase of the object, the textbutton of the same does not move from the store to the inventory.
I’ll leave pictures so you can see how my GUI is structured.

WHAT SOLUTIONS I HAVE TRIED:
If I’m honest, I haven’t tried much, I’m pretty short on time and I only do this for fun, but this is already starting to stress me out! I’ve tried to see if I have any errors in the script, something I’ve put wrong, not calling the function at the right time or something like that, but I haven’t found anything.

local gunList = frames.GunList

local shopFrame = mainFrame.Frames.Shop
local shopList = shopFrame.List
local shopInfoFrame = shopFrame.itemInfo

local buyButton = shopInfoFrame.Buy
local toolImageSP = shopInfoFrame.ToolImage
local toolPrice = shopInfoFrame.Precio
local toolNameSP = shopInfoFrame.Nombre


local inventoryFrame = mainFrame.Frames.Inventory
local inventoryList = inventoryFrame.List
local inventoryInfoFrame = inventoryFrame.itemInfo

local equipDeEquipButton = inventoryInfoFrame.Equip
local toolImageIN = inventoryInfoFrame.ToolImage
--local toolPrice = inventoryInfoFrame.Precio
local toolNameIN = inventoryInfoFrame.Nombre


local selectedItemSP = ""
local selectedItemIN = ""

local selectedItemPrice
local currentGun = jugador:FindFirstChild("currentGun")

------------------------------------------------------------------ ORGANIZACION DE GUIS

local function checkIfPurchased(itemName)
	return checkPurchaseFunction:InvokeServer(itemName)
end

-- Refrescar lista de armas al abrir la tienda
local function refreshGunList()
	for _, button in pairs(gunList:GetChildren()) do
		if button:IsA("TextButton") then
			local itemName = button.Name
			if checkIfPurchased(itemName) then
				button.Parent = inventoryList
				print(itemName, "a sido movido a el inventario")
			else
				button.Parent = shopList
				print(itemName, "a sido movido a la tienda")
			end
		end
	end
end

-- Llamada inicial para cargar listas
refreshGunList()
------------------------------------------------------------------ SHOP

-- Función para actualizar botones de compra
local function updateBuyButton(itemName)
	if itemName ~= "" and checkIfPurchased(itemName) then
		buyButton.Visible = false
	else
		buyButton.Text = "Comprar"
		buyButton.Visible = true
	end
end


-- Cuando el jugador selecciona un ítem en la tienda
for _, v in pairs(shopList:GetChildren()) do
	if v:IsA("TextButton") then
		v.MouseButton1Click:Connect(function()
			selectedItemSP = v.Name
			selectedItemPrice = v.Price.Value

			toolNameSP.Text = v.Name
			toolImageSP.Image = v.ItemImage.Image
			toolPrice.Text = "$" .. v.Price.Value

			updateBuyButton(selectedItemSP)
		end)
	end
end


-- Al hacer clic en el botón de compra
buyButton.MouseButton1Click:Connect(function()
	if selectedItemSP ~= "" then
		local success = buyItemFunction:InvokeServer(selectedItemSP, selectedItemPrice)
		if success then
			print("Ítem comprado: " .. selectedItemSP .. ", por la cantidad de: $" .. selectedItemPrice)
			refreshGunList()
			updateBuyButton(selectedItemSP)
		else
			print("Error en la compra.")
		end
	end
end)

image

1 Like

I feel really dump! Haha, I found the problem, basically when changing the parent of the buttons and wanting to use the refreshgunlist function, this function is not able to find the weapon buttons because they are no longer in the gunlist! The only thing I had to do was copy the buttons and then change the parents.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.