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

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

Asked by 5 years ago

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

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

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
0
Ok, i will try thank you! ChefDevRBLX 90 — 5y
0
It still lets me buy it more than once. ChefDevRBLX 90 — 5y
0
Do the same just after --do code set db to true NewGPU 36 — 5y
0
ok ChefDevRBLX 90 — 5y
0
Partially works, I can only buy 1 item but 1 item only and the text doesnt chance ChefDevRBLX 90 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Check if the player has the item in their backpack, startergear or character. lua if not (player.Backpack:FindFirstChild(itemName) or player.Character:FindFirstChild(itemName) or player.StarterGear:FindFirstChild(itemName)) then -- add item to backpack end

0
IT didnt work. ChefDevRBLX 90 — 5y

Answer this question