US Trends

how to make sell lemons with leaderstats K to 1St in roblox

Here’s the simplest way to make a Sell Lemons system using leaderstats in Roblox: give each player a lemons stat and a money stat, then when they click a sell button, convert all lemons into cash and reset lemons to 0. The basic logic is: money += lemons * pricePerLemon, then lemons = 0.

Server setup

Put the currency values in leaderstats so Roblox shows them on the player list. A common setup is Money and lemons as IntValue objects under a leaderstats folder inside each player.

lua

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local money = Instance.new("IntValue")
	money.Name = "Money"
	money.Value = 0
	money.Parent = leaderstats

	local lemons = Instance.new("IntValue")
	lemons.Name = "lemons"
	lemons.Value = 0
	lemons.Parent = leaderstats
end)

Sell script

Use a sell action that checks whether the player has at least 1 lemon, then pays them for every lemon they have and clears the amount afterward.

lua

local pricePerLemon = 2

script.Parent.ClickDetector.MouseClick:Connect(function(player)
	local leaderstats = player:FindFirstChild("leaderstats")
	if not leaderstats then return end

	local lemons = leaderstats:FindFirstChild("lemons")
	local money = leaderstats:FindFirstChild("Money")
	if not lemons or not money then return end

	if lemons.Value >= 1 then
		money.Value = money.Value + (lemons.Value * pricePerLemon)
		lemons.Value = 0
	end
end)

Button version

If you want a UI button instead of a physical part, use a RemoteEvent so the server handles the money update safely. That keeps players from directly changing their own cash locally.

lua

-- LocalScript inside the button
script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.SellLemons:FireServer()
end)



lua

-- Server Script
game.ReplicatedStorage.SellLemons.OnServerEvent:Connect(function(player)
	local leaderstats = player:FindFirstChild("leaderstats")
	if not leaderstats then return end

	local lemons = leaderstats:FindFirstChild("lemons")
	local money = leaderstats:FindFirstChild("Money")
	if not lemons or not money then return end

	local pricePerLemon = 2
	if lemons.Value > 0 then
		money.Value += lemons.Value * pricePerLemon
		lemons.Value = 0
	end
end)

Common mistakes

  • Using <= 1 when you mean “has at least one lemon”; >= 1 is the correct check for selling.
  • Changing leaderstats from a LocalScript instead of the server.
  • Forgetting to create the Money or lemons values before selling.

Example

If a player has 15 lemons and the price is 2 per lemon, they get 30 money, and their lemons drop to 0. That is the whole sell cycle in one click.

TL;DR

Use leaderstats, track lemons and Money, then on sell do:

lua

Money.Value += lemons.Value * pricePerLemon
lemons.Value = 0

If you want, I can turn this into a full Roblox Studio setup with a GUI button, RemoteEvent, and anti-exploit protection.