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

Can you read specific characters from a string?

For example

playerstats = "5565320"

(Where LVL = "55" & XP = "65,320")

Could you do something to find what characters #3 thru #7 read, returning "65320"?

If this is possible please answer with the function.

I'm trying to use this to make a players datastore one singular string but reading out dozens of information, therefore not even coming close to the datastore limit and making datastores more efficient (for me anyways).

1 answer

✓ Accepted answer
local PrepareS = function(String)
	local String = tostring(String)  -- Allows you to run the code with numbers.
	local Pattern = "%d%d"
	local XP = String:sub(3, string.len(String))
	local Lvl = String:match(Pattern)
	return Lvl, XP
end

print(PrepareS("2358394"))  -- Just examples of it working.
print(PrepareS(23594))
print(PrepareS(12458))

There ya go.

Pattern is for the first two digits, it searches the given string for the first two digits. The sub() function then shortens another version of the string to the 3rd digit and the end of the string and then returns that. Should be what you need. (Also, input is a string so if you input numbers it won't work so just run to string first.)

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