Invalid argument expected with string.lower

local player = game:GetService("Players")
local http = game:GetService("HttpService")

function getFullName(parName)
	local foundPlayer = nil
	
	local Players = game.Players:GetPlayers()
	for i=1, #Players do
		local currPlayer = Players[i]
		
		if string.lower(currPlayer):sub(1, #parName) == string.lower(parName) then
			foundPlayer = currPlayer.Name
			break
		end
	end
	
	return foundPlayer
end

function checkTool(char)
	for _,v in pairs(char:GetChildren()) do
		if v:IsA("Tool") then
			return true
		end
	end
end

function getTool(char)
	for _,v in pairs(char:GetChildren()) do
		if v:IsA("Tool") then
			return v
		end
	end
end

function executeHandTo(player, victim, tool)
	local vplayer = game:GetService("Players"):FindFirstChild(victim)
	local vBackpack = vplayer.Backpack
	
	tool.Parent = vBackpack
	
    --// MAIN GAME ONLY \\ --	
	
	--local leaderstats = player:WaitForChild("leaderstats")
	--local points = leaderstats:FindFirstChild("Point")
	--local pointAdded = 1
	
	--points = tonumber(points.Value)
	--points = points + pointAdded
	--points = tostring(points)
	local Webhook = "notshowingwebhook"
	local data = 
		{
			["embeds"] = {{
				["title"] = "[TC] Hand-To-Logs";
				["description"] = tostring(player.Name) .. "handed a "..tostring(tool.Name).." to "..vplayer.Name;
				["color"] = tonumber(0xf3e28f); 
			}}
		}

	local finaldata = http:JSONEncode(data) 
	http:PostAsync(Webhook, finaldata)
end

player.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		plr.Chatted:Connect(function(msg)
			msg = msg:split(" ")
			if plr:GetRankInGroup(14193454) >= 5 then
				if msg[1] == "!handto" then
					if getFullName(tostring(msg[2])) then
						local e = checkTool(char)

						if e == true then
							executeHandTo(plr, msg[2], getTool())
						end
					end
				end
			end		
		end)
	end)
end)

In an output I get:
ServerScriptService.In-Game Command.handto:11: invalid argument #1 to ‘lower’ (string expected, got Instance)

Why is this happening? I have tried many ways I can think of, but I cannot solve the issue.

I think you forgot to add .Name for currPlayer

if string.lower(currPlayer.Name):sub(1, #parName) == string.lower(parName) then
1 Like

To make it simpler, you can use string:lower() instead.

Your usage of the string library should be consistent, on some occasions you’re calling its operations as functions and on others as methods.