I am making a custom admin panel, and am making a kick feature.
I’m making it so that players can just type in the short name, example:
chicken instead of ChickenCrat, however, I have an issue when it comes to the capitalization.
My script finds chickencrat, but doesn’t kick since the name has capitals and I’m not sure how to get around this.
I’m sure the solution is rather simple, I’ve looked everywhere but couldn’t find it.
To summarise, I want something that could kick people regardless of capitals,
player types chi, script gets chickencrat, ChickenCrat gets kicked even with the 2 capitals.
I’ve tried your code, and it says "True isn’t a valid member of Players “Players”
Would you know a way to change the boolean to a string, which I can kick with?
the function works like this, even shortned names work:
function getUser(stringName)
stringName = string.lower(stringName)
for i, v in pairs(game.Players:GetPlayers()) do
if string.sub(string.lower(v.Name),1,#stringName) == stringName then
return v
end
end
return nil
end
local kick = game.ReplicatedStorage.remoteEvents.playerKick
kick.OnServerEvent:Connect(function(plr, name)
local shortName = name
shortName = string.lower(shortName)
for _,plr in pairs(game.Players:GetChildren()) do
local fullName = string.lower(plr.Name)
if shortName == string.sub(fullName,1,string.len(shortName)) then
game.Players[fullName]:Kick("You have been kicked from the game by an Admin")
else
game.ReplicatedStorage.remoteEvents.kickClient:FireClient(plr)
end
end
end)
local kick = game.ReplicatedStorage.remoteEvents.playerKick
kick.OnServerEvent:Connect(function(plr, name)
local foundPlayers = {}
local lowerSearch = string.lower(name)
for _, player in pairs(game.Players:GetPlayers()) do
local lowerName = string.lower(player.Name)
if string.match(lowerName, "^"..lowerSearch) then
table.insert(foundPlayers, player)
end
end
if #foundPlayers == 1 then
foundPlayers[1]:Kick("You have been kicked from the game by an Admin")
else
game.ReplicatedStorage.remoteEvents.kickClient:FireClient(plr)
end
end)
This will also prevent ambiguous searches from kicking players (a search term which matches the names of multiple players).