Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

2 comments

0

Line 17 dont use the = only use the >

0

if player already has the tool then destroy the gui else dont destroy the gui

2 answers

✓ Accepted answer

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

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!

6 comments

0

that just made it not work,

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

0

Oh I see make make it tool.Name in arguments not just tool my bad

0

Ill try

0

It still does not work

0

I just ended up destroying the script after it says owned and gives the tool and it worked.

This discussion is preserved as it was. New answers, comments, and votes are closed.