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

How could I make this string manipulation exact?

I'm creating an admin console for a friend's clan, and when you enter the player's name in the command box, I want an underlying TextLabel to predict who the player is, or at least match the first found player. Anyways, it works pretty well like so:

Gif: GIF 1

But if I wanted to predict the name of "Jojo6565", and I put "ojo" instead of "jojo", it would still predict it, and I don't want that.

Gif: GIF 2

Here's the string manipulation code I have to get the name of the player:

string.match(string.lower(player.Name),text:sub(cmd:len() + 2).."%w+")

I guess my question is, how can I make it get the name using only the first couple of letters, and not a few letters anywhere in the player name?

1 comment

0

just make sure that the first couple of characters are the same before displaying them. Easy to do with just an if statement

1 answer

✓ Accepted answer

You can check if the first already completed letters match the letters of autofill, like this.

local cmdbar = nil --Insert where the command bar is.
cmdbar.Changed:connect(function()
	local autofill = string.match(string.lower(player.Name),text:sub(cmd:len() + 2).."%w+")
	local alreadyTyped = string.len(tostring(cmdbar.Text))
	if string.sub(autofill, 1, alreadyTyped) == cmdbar.Text then
		--Do the autofil stuff.
	end
end)

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