Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you make a buy button allow you to only buy a tool once?

Asked by 5 years ago

So everything is fine just when it says Owned, you can buy the weapon more than once, how do I make it to where you can only buy it once?

local player = game.Players.LocalPlayer

local rs = game.ReplicatedStorage

local tool = rs.HyperlaserGun

local stats = player.leaderstats

local button = script.Parent

price = 100



script.Parent.MouseButton1Click:Connect(function()

if stats.Cash.Value >= price then

button.Text = 'Owned'

stats.Cash.Value = stats.Cash.Value - price

local clone = tool:Clone()

clone.Parent = player.Backpack

local cloneforstartergear = tool:Clone()

cloneforstartergear.Parent = player.StarterGear

else

button.Text = 'Failed'

wait(1)

button.Text = 'Buy'

end

end)
0
Line 17 dont use the = only use the > Gameplayer365247v2 1055 — 5y
0
if player already has the tool then destroy the gui else dont destroy the gui Gameplayer365247v2 1055 — 5y

2 answers

Log in to vote
1
Answered by
crazlo6 20
3 years ago

I know I am late but you can just disable the script after the whole script

Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

So, to solve your problem you want to check if they don't already own the item . If they don't they will be able to buy it so the line before this :

if stats.Cash.Value >= price then

button.Text = 'Owned'

add this :

if player.Backpack:FindFirstChild(tool) == nil and player.StarterGear:FindFirstChild(tool) == nil then
    ...
end

And if they are buying something else and want to equip you would want to check the datastore and see if they own it. Hope this helps!

0
that just made it not work, ChefDevRBLX 90 — 5y
0
How so? It’s checking if u already own the tool . If there is no tool in backpack and starter gear then it will let u buy . Otherwise it won’t . Must mean u have the tool AnonymousDeveloper13 22 — 5y
0
Oh I see make make it tool.Name in arguments not just tool my bad AnonymousDeveloper13 22 — 5y
0
Ill try ChefDevRBLX 90 — 5y
View all comments (2 more)
0
It still does not work ChefDevRBLX 90 — 5y
0
I just ended up destroying the script after it says owned and gives the tool and it worked. ChefDevRBLX 90 — 5y

Answer this question