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

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

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?

2 comments

0

you're passing an Object in the userName variable. i assume userName will be a player. check where you fire the function.

0

it's called an argument

1 answer

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

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