Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how can i make it so a surfacegui textlabel only shows a maximum of 4 characters?

i'm making a car with a chassis that has a values folder, and i'm also making a script that changes a textlabel to display the car's current rpm, but since the rpm's value is EXACT, so the value can have 16 decimal points, so i want to avoid the text accidentally displaying the decimal point or one of the decimal numbers, is there a way to avoid the text showing over 4 characters?

any help is greatly appreciated, thanks!

1 answer

✓ Accepted answer

Time to walk you through the process of doing this.

First thing first - we'll need a number for testing purposes. This will be the car's rpm, but since I cannot access it a placeholder number will be used instead.

local number = 51.14918491041485861 -- Placeholder, I may or may not of spammed my keyboard. This should be your cars rpm!

Now, this is a number. And we want to get the first 4 digits. But we can't do that from a number, so we'll need to convert it to a string.

local number = 51.14918491041485861 -- Placeholder, I may or may not of spammed my keyboard. This should be your cars rpm!
local stringnumber = tostring(number)

The number is now a string. We can use string.sub to get the first 4 characters.

local number = 51.14918491041485861 -- Placeholder, I may or may not of spammed my keyboard. This should be your cars rpm!
local stringnumber = tostring(number)
local four = string.sub(stringnumber, 0, 4)

We are telling the string.sub to start at the 0th character and go to the 4th character. Now, we have the first four characters.

2 comments

0

thanks a lot!

0

No problem - happy to help!

This discussion is preserved as it was. New answers, comments, and votes are closed.