Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Grabbing the last three digits of a userID?

Asked by 6 years ago
Edited 6 years ago

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

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

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

0
This is great. I've been stressfully trying to find something along these lines to help with this project. Thanks for the help. BritishActuaI 44 — 6y
0
A side-note: It was made as a localscript. Just do the edits to player variable yourself, I guess. ZeExplosion 210 — 6y
Ad

Answer this question