Hi, I’m looking to make a script that locates a certain model and was wondering how I’d go about this -
For example, say the Models name is “#038_Boxite” - How would I go about ignoring the #038_ and only receive the name?
Additionally to this, how would I go about JUST getting the first three also, so say I wanted to find the 38th one in a list, how would it be located through “#038” - Thanks! This is my first time working on something like this.
Hey there!
You can do this by using string.sub(…)
More information about this is in the roblox API documents. If you have questions let me know, I’m currently on mobile so sorry for the short answer
If you’re specifically looking for letters, you can use string.match. A pattern to find just letters is %a+, while one that just ignores numbers and punctuation would be [^%d%p]+. You can just do model.Name:match(pattern). The difference is that the second one allows whitespace (spaces and tabs) while the first one only allows letters.
If your model’s name always follows the same format, you can just use string.sub with a specific number.
Consider using string.match as it can account for an arbitrary amount of digits over hard-coding the start and ending number of the string.
local number = splitString[1]:match("%d+")
This pattern will catch the first number and all subsequent characters until the next character is not a number, then terminate the search and return the characters that were found.