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)
COMMUNITY QUESTION
How do you make it so that you can only buy one on the same item in the shop?
1 answer
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.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Move your if statement inside the event