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

How can you make a buy button only buy the tool once?

So I have a buy button in a shop and you can buy the item more than once. How do I make it to where you can't buy it again and to where the text says "Bought"?

local price = script.Parent.Parent.Price

local tools = game.ReplicatedStorage:WaitForChild("Tools")

local tool = script.Parent.Parent.ItemName

local player = script.Parent.Parent.Parent.Parent.Parent.Parent

  

script.Parent.MouseButton1Click:connect(function()

if player.leaderstats:FindFirstChild("Money").Value >= price.Value then

player.leaderstats:FindFirstChild("Money").Value = player.leaderstats:FindFirstChild("Money").Value - price.Value

game.ReplicatedStorage.ShopBuy:FireServer(tool.Value)

end

end)

2 answers

Try making a value that changes after you have brought the tool and then check if that value is true or false.

[example]

local db = false
script.Parent.MouseButton1Click:Connect(function()
	if db == false then
		--do code
	elseif db == true then
		--Say that its already brought!
end

5 comments

0

Ok, i will try thank you!

0

It still lets me buy it more than once.

0

Do the same just after --do code set db to true

0

ok

0

Partially works, I can only buy 1 item but 1 item only and the text doesnt chance

Check if the player has the item in their backpack, startergear or character.

if not (player.Backpack:FindFirstChild(itemName) or player.Character:FindFirstChild(itemName) or player.StarterGear:FindFirstChild(itemName)) then
-- add item to backpack
end

1 comment

0

IT didnt work.

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