Okay, so everything is being created in the inventory when I buy the item the first time, but the second time I want to buy the item, I just want it to add 1 to a value that's in the item, but I keep getting this:
14:40:02.823 - Players.rak553.PlayerGui.aShop.ShopFrame.BuyFrame.BuyButton.Buy:30: attempt to index field 'ItemAmount' (a nil value)
This is the broken line:
Inventory.name.ItemAmount.Value = Inventory.name.ItemAmount.Value + 1
That's the whole code, please help me!
local plr = game.Players.LocalPlayer
local button = script.Parent
local Item = Instance.new('Folder')
local ItemType = Instance.new('StringValue')
local ItemAmount = Instance.new('NumberValue')
local moneyAmount = plr.Money.Amount.Value
local Inventory = plr.Inventory
button.MouseButton1Click:connect(function()
local price = script.Parent.Price.Value
local name = script.Parent.ItemName.Value
local typeName = script.Parent.ItemType.Value
if (moneyAmount >= price) then
moneyAmount = moneyAmount - price
if (not Inventory:FindFirstChild(name)) then
--Create Item
Item.Parent = Inventory
Item.Name = name
--Create Item Type and Set it
ItemType.Parent = Item
ItemType.Name = "ItemType"
ItemType.Value = typeName
--Create ItemAmount and Set it
ItemAmount.Parent = Item
ItemAmount.Name = "ItemAmount"
ItemAmount.Value = 1
else
Inventory.name.ItemAmount.Value = Inventory.name.ItemAmount.Value + 1
end
end
end)

2 comments
Thank you so much, it worked! :)
@rak553 then accept his answer