So I am writing an admin script and I want the admins to be able to do :kick others for example or :fly me. So far I have made an admin and nonadmin parameter but it doesn’t work.
local Players = game:GetService("Players")
local function get_player(name: string): Player | nil
name = name:lower()
if name == "admins" then
for _, player in pairs(Players:GetPlayers()) do
if player.Rank.Value > 0 then
return player
end
end
elseif name == "nonadmins" then
for _, player in pairs(Players:GetPlayers()) do
if player.Rank.Value == 0 then
return player
end
end
else
---------------------------------------------------------------------------------
--Retrieving the player without their full username and not being key sensitive--
---------------------------------------------------------------------------------
for _, player in ipairs(Players:GetPlayers()) do
if name == player.Name:lower():sub(1, #name) then
return player
end
end
end
return nil
end
In the actual commands themselves, I have:
local args = msg:sub(7):split(" ");
local player = get_player(args[1])
This bit here is responsible for finding the player regardless whether the admin types in the full username and it works:
for _, player in ipairs(Players:GetPlayers()) do
if name == player.Name:lower():sub(1, #name) then
return player
end
end
But the admin and nonadmin parameter don’t.
I can elaborate if needed.