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

How do you make it so that you can only buy one on the same item in the shop?

Asked by 6 years ago
local player = game.Players.LocalPlayer
local leaderboard = player:WaitForChild("leaderstats")
local button = script.Parent
local price = button:WaitForChild ("Price")
local item = button:WaitForChild ("ItemName")
local rs = game:GetService ("ReplicatedStorage")

found = false
if player.Backpack:FindFirstChild('Normal Key') then
    found = true
end

button.MouseButton1Click:connect(function()
    if leaderboard.Money.Value >= price.Value and found == false then
        leaderboard.Money.Value = leaderboard.Money.Value - price.Value
        local item = rs:WaitForChild(item.Value)
        item:Clone().Parent = player.StarterGear
        item:Clone().Parent = player.Backpack
    end
end)
0
Move your if statement inside the event Goulstem 8144 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

You should change your code to like this:

button.MouseButton1Click:connect(function()
if player.Backpack:FindFirstChild('Normal Key') and leaderboard.Money.Value >= price.Value 
then
    leaderboard.Money.Value = leaderboard.Money.Value - price.Value
    local item = rs:WaitForChild(item.Value)
    item:Clone().Parent = player.StarterGear
    item:Clone().Parent = player.Backpack
else
    button.Text = You already have this item!
end
end)

That's should be the code, make sure then is on the same line as the if statement.

Ad

Answer this question