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