Help with Text Buttons

Hello there! I would like someone that can help me with a problem I have.
So I’m currently making a game, where you buy stuff and get it into the inventory and some other stuff.

I would like to know how I would fix this issue. When I activate the Buy UI for the first time, The “Buy” button works perfect. But when I close it, and activate it again. The buy button doesn’t work. Here’s a video.

The UI is cloned from replicated Storage to the PlayerUI.

I rewrote the script and even check what was wrong while playing it. But it seems like everything is perfect. Only the button is not working.

Any help is appreciated!*

You will need to show us the code for the button to solve this issue.

3 Likes

Alright. Here it is.

local buybutton = script.Parent
local ItemImage = game.Players.LocalPlayer.PlayerGui:WaitForChild("Inventory").Item
local Quantity = buybutton.Quantity
local item = game.Workspace.ShopItems:FindFirstChild(script.ItemName.Value)
local ItemsToGive = item.Item.ItemsToGive
local Name = ItemsToGive.Parent.ItemName
local Main = game.Players.LocalPlayer.PlayerGui:WaitForChild("Inventory").Main

buybutton.MouseButton1Click:Connect(function()
	if Main:FindFirstChild(Name.Value) then
		local item = game.Players.LocalPlayer:WaitForChild("Inventory").Main[Name.Value]
		item.Count.Value = item.Count.Value + ItemsToGive.Value
		item.ItemsNumber.Text = "x".. item.Count.Value
		print("Only the original item was changed")
	else
		local clone = ItemImage:Clone()
		clone.Name = Name.Value
		clone.Parent = Main
		clone.ItemName.Text = Name.Value
		clone.Count.Value = clone.Count.Value + ItemsToGive.Value
		clone.ItemsNumber.Text = "x".. clone.Count.Value
		clone.Visible = true
		print("Everything works!")
	end
	if ItemsToGive.Value == 0 then
		buybutton.Text = "Can't purchase 0 objects. Please select at least 1"
		wait(1)
		buybutton.Text = "Buy"
	end
	ItemsToGive.Value = 0
	buybutton.Parent.Quantity.Text = "0"
end)

Do you also need the Clone UI script?

Hey,
I noticed in the code you provided on line 11 you forgot to call PlayerGui:

local item = game.Players.LocalPlayer.PlayerGui:WaitForChild("Inventory").Main[Name.Value]
2 Likes

Ohhh yeah. Thank you for the checkout. I will see if it solves my problem as well!

Thank you so much! It solved my problem! :smiley:

1 Like