Get player if typed with lower case

Hi, I’m working on a command and it all works but it is Capital Sensitive. Meaning that if it misses a Capital, it doesn’t work. I realized that HD Admin doesn’t have that issue so there must be a fix to that.

Currently I have a function that gets the players full name if they type half of their name.

local function getFullName(message)
		local userAffected = string.sub(message, string.find(message," ",1,false) + 1, string.len(message))
		local userFinal = string.sub(userAffected, 1, string.find(userAffected, " ",1,false)-1)
		
		if players:FindFirstChild(userFinal) ~= nil then
			return userFinal
		else
			for v,i in pairs(players:GetChildren()) do
				if string.sub(i.Name, 1, string.len(userFinal)) == userFinal then
					return i.Name
				end
			end
		end
		return false
	end

Please help.

function getFullName(message)
	-- assuming the message has this format: command, player
	local target = string.lower(string.match(message, "%s(.+)"))
	
	for _, player in pairs(players:GetPlayers()) do
		if string.find(string.lower(player.Name), target) then
			return player.Name -- first name found
		end
	end
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.