Script not finding player

I’m trying to create a custom admin, but with a simple command whenever I try to find the player, it returns “nil”. Does anyone know why it’s not returning anything? It registers the print outs of the sender and arguments perfectly.

local commands = {}

local function findPlayer(name)
	for i, v in pairs(game.Players:GetChildren()) do
		if string.lower(v.Name) == name then
			return v
		end
	end
end

commands.goto = function(sender, arguments)
	print(sender)
	print(arguments)
	
	local teleportingPlayer = findPlayer(sender)
	local teleportingTo = findPlayer(arguments[1])
	
	if teleportingPlayer and teleportingTo then
		teleportingPlayer.Character.HumanoidRootPart.CFrame = teleportingTo.Character.HumanoidRootPart.CFrame
		
		print("Teleported")
	end
end

Maybe the name in the findPlayer isn’t all lowercase. Try this:

if string.lower(v.Name) == string.lower(name) then
	return v
end

image

I fixed it by converting the “name” to a string. All good now.

Sorry, i didn’t know the name was an instance

if string.lower(v.Name) == string.lower(name.Name) then
	return v
end

(just change name to name.Name)

local formatName = string.lower(name)

if string.lower(v.name) == formatName then
 return v
end

If name is Instance then you can do like this

if v == name then
	return v
end