I made a tool shop system where you click a part and it gives the item you purchased if you have enough money. But there’s one problem, If I have enough money, I can purchase the tool multiple times. Is there a way to stop this? (sorry if I don’t make sense)
Subtract the cost from the player’s balance
It’s kind of hard to help you with no code. If you can provide your script, we can help you more.
local price = 400
local db = true
local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local backpack = player:WaitForChild(“Backpack”)
local folder = game.ServerStorage.Tools
script.Parent.ClickDetector.MouseClick:connect(function(player)
if backpack:FindFirstChild(folder.Coconut)then
db = true
elseif player.leaderstats.Coins.Value >= price then
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - price
db = false
game.ServerStorage.Tools.Coconut:Clone().Parent = player.Backpack
db = true
end
end)
You can check if the player already has the item. If they do, don’t give them the item.
@SpaceDice999 is right but you’ll have to save your item names into a datastore when purchased, then you can load these item names and match them with a list of items. (or a folder of items) then if any item names match you just give them back to the player when they join the game.
--save a string and parse it when you need to load it.
local inventory = "item1,item2,item3"
--OR you can just save a table
local inventory = {"item1", "item2", "item3"}
--save item names to a datastore.
ds:SetASync(""..player.UserId, inventory)
there is a little bit more to it then this, but that’s the basics. (I wouldn’t just copy/paste this code)
Use FindFirstChild to search for the tool in the players backpack:
local player = game.Players.LocalPlayer
local tool = player.Backpack:FindFirstChild("TOOLNAMEHERE")
if not tool then
("Award tool here")
end
This helped me. I copied this code and modified it a bit. Thank you for your help!