The following code always returns nil which is there error(there is more into the script but this is what I need to be fixed)
1 | function SearchPlr(text) |
2 | for i, v in next ,game.Players:GetPlayers() do |
3 | if string.find(v.Name, "^" ..text) then |
4 | return v.Name:lower() |
5 | end |
6 | end |
7 | end |
No matter what I do v:lower() or v.Name:lower() it always returns nil =/
You should use a lowercase version of both the search text and the text to be searched in:
1 | if v.Name:lower():find( "^" .. text:lower() ) then |
Though, instead of using find
and the caret, it might be wiser to just use substrings:
1 | if v.Name:sub( 1 , #text):lower() = = text:lower() then |
Sure, I can.
1 | function SearchPlr(Text) --Your function. |
2 | for i,v in pairs (game.Players:GetPlayers()) do --Gets all the players in the game. |
3 | if v.Name:lower():find(Text:lower()) or v.Name:lower() = = Text:lower() then --See's if the player's name matches the Text or has part of the Player name as the text. |
4 | return v.Name:lower() --Returns the player name lowered. |
5 | end |
6 | end |
7 | end |