How to sell all "Lemons" with one click

  1. What do you want to achieve? To sell all lemons with one click and get as much money as I sold lemons

  2. What is the issue?

if Plr.leaderstats.lemons.Value <= 1 then
		Plr.leaderstats.Money.Value += 2
		Plr.leaderstats.lemons.Value -= 1 
  1. What solutions have you tried so far? I searched and tried for 1-2 minutes but did not find anything and did not work
2 Likes

is if Plr.leaderstats.lemons.Value <= 1 then on purpose or accident? because what you’re checking is if the player has equal or smaller amount of “lemons” here, so if player has 2 lemons or more, this check will not go through

3 Likes

By chance I experimented. I wanted to write "If the player has lemons then " And I just couldn’t think of anything else.

3 Likes

you should’ve use if Plr.leaderstats.lemons.Value >= 1 then for checking if player has lemon(s)

1 Like

mmm good, but how to make it so that you can sell in one click? and receive currency for it?

Something that could work should be like this:

local player = game.Players.LocalPlayer
local lemons = player.leaderstats.lemons
local money = player.leaderstats.Money

if lemons.Value > 1 then
	local soldLemons = lemons.Value
	local earnedMoney = soldLemons * 2

	-- Update the money and lemon counts
	money.Value = money.Value + earnedMoney
	lemons.Value = lemons.Value - soldLemons
end

The script checks if the number of lemons (lemons.Value) is greater than 1. If it is, it calculates the number of lemons sold (soldLemons) and the corresponding amount of money earned (earnedMoney). It then updates the money count (money.Value) by adding the earned money and decreases the lemon count (lemons.Value) by the number of lemons sold.

You can place this script in a LocalScript within a Button or ImageButton object’s Click event to execute the code when the button is clicked. Make sure to replace Plr with player if you are using the player variable as shown in the script.

3 Likes

Hello BOOC2002,
I would solve that, by first creating a variable called “PricePer Lemon” which defines the price of one single lemon and then multiplying your lemons value by 2 to get the total cash you would get if you’d sell every lemon. After that it resets your lemons.

local PricePerLemon = 2 --Im unsure if it is 2, just change it if im wrong
local Lemons = Plr.leaderstats.lemons --if you have to use the lemons path multiple times
local Money = Plr.leaderstats.Money -- same thing as lemons variable

if Lemons.Value >= 1 then
Money.Value += (Lemons.Value * PricePerLemon) --Add the Lemons amount multiplied by the Price per Lemon in Cash
Lemons.Value = 0 --set lemon value to 0
end
2 Likes

I like both scenarios so I will mark you 2
Script Edit @toomanynighhts

if lemons.Value > 1 then
	local soldLemons = lemons.Value
	local earnedMoney = soldLemons * 2

	-- Update the money and lemon counts
	money.Value = money.Value + earnedMoney
	lemons.Value = lemons.Value - soldLemons
end

or Edit from @xavocs

if Lemons.Value >= 1 then
Money.Value += (Lemons.Value * PricePerLemon) --Add the Lemons amount multiplied by the Price per Lemon in Cash
Lemons.Value = 0 --set lemon value to 0
end

thx whare much @xavocs @toomanynighhts

why do you mark yourself as the solution? the solution should either be @toomanynighhts or @xavocs both of them tried and help you and you should’ve mark the one that work best for you

I like both scenarios. How do I mark two of them?? I would Tag them both But I don’t know how. so I put it on myself but pointed out who created the script

Mark the one that gave the solution the quickest and work the best, there’s no point of having 2 victor in a competition. plus, we take the amount of solutions on this forum as a badge for our hard work

Unfortunately, this isn’t a good approach as you might want that data to be saved. Sending it through remotes isn’t optimal as it can be exploited, too.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.