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

How would I get the player in string manipulation?

So I'm making a script where you can get the ping of yourself and other players as well. I have the ping for myself done but I'm not sure quite what to do for this part here. I want it to be so you can say !ping play and It'd get the ping of Player1. How would I make it fill in the rest of the players' name.

More examples: !ping xxsa -- would get the ping of xxSalvAGExx

So far I got this.

Player.Chatted:connect(function(Message)
	if string.sub(string.lower(Message, 1, 6)) == "!ping " and game.Players:FindFirstChild(string.sub(string.lower(Message, 7))) then
--nothing here yet
end

This works fine but you need to type the players' name fully and correctly which just isn't really what I wanted.

2 comments

0

Use string.find or string.match, what you're doing right now will only get the player if you supply the full name.

2 answers

✓ Accepted answer

With the characters given from the command, see if those characters match with anyother player's name.

for _,v in pairs(game.Players:GetPlayers()) do
       if v.Name:lower():sub(1, (#msg:sub(7))) == msg:sub(7) then
              print(v.Name.. ' matches')
       end
end

1 comment

0

Or could use string.match or string.find

You would just loop through the players and test to see if string.sub(name,1,string.len(play)) equals someone's name, and from there you would have to determine what you would want to do if two or more people had the same start in their name.

You could also use string.lower or string.upper to make all the word's letters uppercase or lowercase to eliminate the need for case sensitive testing.

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