Finding the prefix of a string

Hello!

I have a few progress systems which are duplicated for every player, the issue is that it can cause a bit of lag, so I am trying to destroy it for the local player. I can do that, the issue is that I don’t know how to find the prefix of the string.

So, each time it’s duplicated for each player, on the server’s side, its name is “progress(user’s id)”. How would I find if the name starts with “progress”?

I tried doing some research, and found string:find(), however that seems to not be in the Roblox Lua library. Where do I go from here?

Roblox has string:find(), it totally exists.

For any object in the library string.function(str), you can just do str:function().

1 Like

When you say string:find(), do I do the string’s variable, or the actual word “string”?

The string’s variable. So:

local str = "hello"

print(str:find("ell")) --2, 4
1 Like

What is the 2,4 at the end? Or is that optional?

No, that is what it prints. Basically, it returns the start of the match and the end. So, ell starts 2 characters in and ends 4 characters in. If it doesn’t find it, it returns nil. So, to catch that, you can do:

local start, End = str:find("ell")
2 Likes
 local str = "progress123"
 if str:find("progress") then -- found, or else it would be nil
    local id, _ = str:gsub("progress", "") -- get the id as well
    print(id)
 end

Another approach would be to see whether the id is contained in there instead of finding out whether ‘progress’ is.

 if str:match("%d") then
   print(str:match("%d+"))  -- gets the id, %w+ for all of it
end
1 Like