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
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.
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
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
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
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.