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

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

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)

1 comment

0

Move your if statement inside the event

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.