Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

bad argument #1 to 'lower' (string expected, got Object)?

Asked by
sonuka 24
6 years ago
function FindPlayer(userName)
    for _, Player in ipairs(game.Players:GetPlayers()) do
        if string.lower(Player.Name) == string.lower(userName) then
        return Player
        end
    end
    end

I get this error: bad argument #1 to 'lower' (string expected, got Object) Help?

0
you're passing an Object in the userName variable. i assume userName will be a player. check where you fire the function. RubenKan 3615 — 6y
0
it's called an argument hiimgoodpack 2009 — 6y

1 answer

Log in to vote
-1
Answered by 6 years ago

try using tostring(param) for both player.Name and userName to garuntee they are both strings.

function FindPlayer(userName)
    for _, Player in ipairs(game.Players:GetPlayers()) do
        if string.lower(tostring(Player.Name)) == string.lower(tostring(userName)) then
        return Player
        end
    end
end
Ad

Answer this question