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

Grabbing the last three digits of a userID?

I'm creating something in-game which requires the last three digits of a userId to display on an epaulette, and I'm wondering how this could be achieved. So far, I've been unable to find a way to grab specific numbers from a string of numbers.

I don't mean for this to be a request, however, is it possible to grab the last three digits of a userID, and how would this be accomplished?

Many thanks,

BritishActuaI

1 answer

✓ Accepted answer

Yes. It is possible.

local player = game.Players.LocalPlayer
print("last is "..string.sub(player.UserId,#tostring(player.UserId)-2,#tostring(player.UserId)))

In this code I made to test it, it will print the last three numbers, using string.sub. A hashtag is used to determine the length of strings. Obviously, the user ID isn't a string, so you must use tostring() to convert it for this. If you need more information,

http://wiki.roblox.com/index.php?title=Global_namespace/String_manipulation#string.sub

Thanks, Explosion

2 comments

0

This is great. I've been stressfully trying to find something along these lines to help with this project. Thanks for the help.

0

A side-note: It was made as a localscript. Just do the edits to player variable yourself, I guess.

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