Adonis Admin Custom Commands Help!

I added a command that can only be used by users with the “Example” role to Adonis admin. This command changes the player’s team and I want to prevent someone with a higher rank than “Example1” from using it. For example, if a user has a rank of 10 as “Example”, I want to prevent someone with a rank of 11 from being able to use the command.

This is what i tried:

Example= {
	Prefix = Settings.Prefix;
	Commands = {"Example"};
	Args = {"me"};
	Description = "Changes your team to Example.";
	AdminLevel = "Example";
	Filter = true;
	Hidden = false;
	Function = function(plr, args, data)
		local newTeam = plr.Team.Name -- Default to the player's current team
		if args[1] == "me" then
			-- Only allow the player to change their own team
			newTeam = plr.Team.Name
		else
			-- If a team name is specified, check if it exists and allow the player to change to it if it does
			local teamName = "Example"
			local team = game:GetService("Teams"):FindFirstChild(teamName)
			if team then
				newTeam = team.Name
			else
				error("'" .. teamName .. "' not valid!")
			end
		end
		-- Set the player's new team
		plr.Team = game:GetService("Teams")[newTeam]
	end
};

Get the PlayerLevel from the data parameter in the function.

1 Like

I tried this and didn’t work.
if data.AdminLevel == ("Example") then

print the data then, see what the admin level is

image

I also tried this didnt work aswell

if data.Level == 1 then

You can use the adonis server service called Admin to get the level of the player:

-- Assuming that you don't want to use a modulescript or function:
local target

for _,player in pairs(game.Players:GetPlayers()) do
    if string.find(player.Name, args[1]) or string.find(player.DisplayName, args[1]) then
        target = player
        break
    end
end

if not target then return end -- No such player found
local AdminLevel = server.Admin.GetLevel(target) -- Gives you a number value

if AdminLevel >= 100 then
    -- Do stuff
end
1 Like

Instead of obtaining the administrator level, would it be possible to get the rank name of the admin level instead?

Not necessarily the same, but a good way to specifically check within your current rank structure:

if AdminLevel == server.Settings.Ranks["Moderator"].Level then
    -- Do stuff
end

or you could do a loop to get the datat table of a rank.

local Rank

for rank,data in pairs(server.Settings.Ranks) do
    if rank.Level == AdminLevel then
        Rank = rank
        break
    end
end
1 Like

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