How to take a number out of a number

First convert the number into a string using tostring() and then use either string.find(), to find a certain part of the number and extract it. I recommend using string.sub though. Here is a link to string.sub: string | Roblox Creator Documentation

If you then need it as a number again use tonumber() to convert your edited string back into a number.

In your case, as I read further on the thread, you are trying to do a conversion system with 5000 alone.

so here is your solution.

local 5000alone = string:sub(1, #str-3)

– Create a variable in which you Perform your operations on the variable we just created (example = local convertednumber = 5000alone/10

– add origin number back to variable (convertednumber)

Happy to help - CyberWizard

Let’s say if the num was 5,405

Then I want to temp remove 405

Let’s say if it’s 3,056

Then temp remove 56

Let’s say it’s 5,021,788

Temp remove 21,788

See that before multiplying by 1000 the value would be 5 using the math.floor() function.

So the string.sub gets rid of the numbers?

Here’s a test script I made:

local coins = 5873
local coins_String = tostring(coins)

local calculate = 10^(string.len(coins_String)-1)  -- Return: 10, 100, 1000, 10000...
local magic = math.floor(coins/calculate)*calculate

local backup = coins-magic

print(magic)
print(backup)

Idk if I did something wrong but I don’t get 5k from it

You’re supposed to floor it. Since just dividing the number would give 5.873 and not 5.000.

2 Likes