Hey developers,
I have a shop gui where a player can buy an item but, can’t buy the same item multiple times.
The problem is that though the player can’t buy the same item multiple times it upon clicking the gui button it will still take away their cash.
The script:
local items = game.ReplicatedStorage:WaitForChild("Items")
game.Players.PlayerAdded:Connect(function(plr)
local ls = Instance.new("Folder")
ls.Name = "leaderstats"
ls.Parent = plr
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Value = 1000
cash.Parent = ls
end)
game.ReplicatedStorage:WaitForChild("OnItemBought").OnServerEvent:Connect(function(plr, itemBought)
if itemBought and itemBought.ClassName == "Tool" and itemBought.Parent == items then
local cash = plr.leaderstats.Cash
if cash.Value >= itemBought.ShopGuiInfo.Price.Value then
cash.Value -= itemBought.ShopGuiInfo.Price.Value
if plr.Backpack:FindFirstChild(itemBought.Name) or plr.Character:FindFirstChild(itemBought.Name) then
return warn("Already owned")
end
itemBought:Clone().Parent = plr.Backpack
end
end
end)
Please help!