1000 coins for 10 gems
1000/1000 = 1 * 10 gems
This is my formula but it seems to be more complicated with numbers such as 1038, 3828290
1000 coins for 10 gems
1000/1000 = 1 * 10 gems
This is my formula but it seems to be more complicated with numbers such as 1038, 3828290
What’s the issue? You need to elaborate a lot on your post because I don’t really see a question aside from the title which isn’t explanatory enough.
I want to know if there is a less complex method of converting currencies
Divide by 100 instead of 1000? It shouldn’t matter anyways, this kind of thing could be done ~200 times a second and still not lag people
How about if the number is 10,052
What about it? Division in lua will return a float value, if you don’t want that you can do math.floor()
on the value you divide.
Well how do I know if the num is 1k,10k,100k
I still don’t understand what you’re trying to ask. If you want to know whether a part is above a certain threshold you can just check that with val > threshold
or val >= threshold
if you want it to be inclusive
I am talking about a currency converting system not a part
Oops, made a typo, regardless the code snippets I sent are referring to numbers, there’s no way to determine if a part is greater than another part (what kind of metric would that be?)
1000 coins for 10 gems ???
This text will be blurred
I genuinely have no clue what you are talking about right now
It literally says it in the title and I told u multiple conversions
You were asking if the conversions were okay, right? They are correct, you can use >=
or >
to check for thresholds, and math.floor()
if you don’t want float values.
I think what he meant to say is only 1000 should be converted to 10, if its a 1002 then there’s a change which is 2.
Something like a while loop would work.
local currency = 1032
local gems = 0
while currency >= 1000 do
gems += 10
currency -= 1000
end
It think something like this should work:
local Leaderstats = game.Players.LocalPlayer.leaderstats.Points
local Leaderstats2 = game.Players.LocalPlayer.leaderstats.Gems
local NewValue = math.floor(Leaderstats.Value, 1000) -- Rounding there leaderstat down to the nearest 1000
local GemsAmount = NewValue / 100 -- Getting amount of gems to give.
Leaderstats.Value = Leaderstats.Value - NewValue
Leaderstats2.Value = Leaderstats2.Value + GemsAmount
I’m not entirely sure what you’re trying to achieve, but math.floor
and the modulus operator should do the trick:
local function coinsToGems(coins: number)
local gems = math.floor(coins / 100) -- Number of gems
local coins = coins % 100 -- Leftover coins
return gems, coins
end