Script:
script.Parent.MouseButton1Down:Connect(function() if game.Players.LocalPlayer.leaderstats.Cash.Value >= 3 then local pistol = game.ReplicatedStorage.Pistol:Clone() pistol.Parent = game.Players.LocalPlayer.Backpack end script.Parent.num.Value = script.Parent.num.Value +1 if script.Parent.num.Value ~= 1 and game.Players.LocalPlayer.leaderstats.Cash.Value < 3 then game.Players.LocalPlayer.Backpack.Pistol:Destroy() script.Parent.Text = "You already own that!" wait(0.5) script.Parent.Text = "Pistol" end end)
So it's like a buying system, if your cash value is more than 3 then you can buy it, also, if you already have one Pistol in your inventory it will not give you another one. But it keeps giving me a pistol even though I already have one in my inventory.
pls help
This here will Give you a Pistol if you have 3 Cash then take it away and clone it it will also make it so it will stay if the player dies. and if the player already has it it wont let them spam it.
local plr = game.Players.LocalPlayer local replicatedstorage = game:GetService("ReplicatedStorage") script.Parent.MouseButton1Click:connect(function() if plr.Backpack:FindFirstChild("Pistol") or plr.StarterGear:FindFirstChild("Pistol") or game.Workspace[plr.Name]:FindFirstChild("Pistol")then script.Parent.Text = "You Own This Item" wait(2.5) script.Parent.Text = "Buy Pistol" else if plr.leaderstats.Cash.Value >= 3 then replicatedstorage.Pistol:Clone().Parent = plr.Backpack replicatedstorage.Pistol:Clone().Parent = plr.StarterGear plr.leaderstats.Cash.Value = plr.leaderstats.Points.Value-3 else local cashrequired = 3- plr.leaderstats.Cash.Value script.Parent.Text = "You Need "..cashrequired.." Cash" wait(2.5) script.Parent.Text = "Buy Pistol" end end end)
Also Make sure this is in a LocalScript