Modifying this script

I want it so the script below works if a staff member runs it (if they have a certain group rank or above)

permission = {"Star_Treks","Player0","Player1"} --People you want to be able to use the teleport command.
command = "!briefing" --The command that when chatted will teleport player to the brick.


jail = script.Parent

function check(name) 
if table.maxn(permission) == 0 then return true end
for i = 1,#permission do 
if (string.upper(name) == string.upper(permission[i])) then return true end 
end 
return false 
end 

function Jail(name) 
local player = game.Players:FindFirstChild(name) 
local torso = player.Character:FindFirstChild("Torso") 
if torso == nil then return end 
local location = {jail.Position} 
local i = 1 

local x = location[i].x 
local y = location[i].y 
local z = location[i].z 

x = x + math.random(-1, 1) 
z = z + math.random(-1, 1) 
y = y + math.random(2, 3) 

local cf = torso.CFrame 
local lx = 0 
local ly = y 
local lz = 0 

torso.CFrame = CFrame.new(Vector3.new(x,y,z), Vector3.new(lx,ly,lz)) 
end 

function onChatted(msg, recipient, speaker) 


local source = string.lower(speaker.Name) 
msg = string.lower(msg) 

if not check(source) then return end 

if string.match(msg, command) then 
local players=game.Players:GetChildren() 
for i=1, #players do 
if string.match(msg, string.lower(players[i].Name)) then 
Jail(players[i].Name) 
return 
end 
end 
end 
end 

function onPlayerEntered(newPlayer) 
newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end) 
end 

game.Players.ChildAdded:connect(onPlayerEntered)

Use Player:GetRankInGroup(GroupId)

like this:

if player:GetRankInGroup(1234567) == 1 then -- checks if the player given is a member, not an admin or owner or anything else
   -- code here
end

DevHub:
https://developer.roblox.com/en-us/api-reference/function/Player/GetRankInGroup

Try this. I modified the check function. make sure to set the group id and min level

local groupId = 123456
local minLevel = 1
command = "!briefing" --The command that when chatted will teleport player to the brick.


jail = script.Parent

function check(name) 
	if game.Players[name] then
		if game.Players[name]:GetRankInGroup(groupId) >= minLevel then
			return true
		else
			return false
		end
	end
end 

function Jail(name) 
	local player = game.Players:FindFirstChild(name) 
	local torso = player.Character:FindFirstChild("Torso") 
	if torso == nil then return end 
	local location = {jail.Position} 
	local i = 1 

	local x = location[i].x 
	local y = location[i].y 
	local z = location[i].z 

	x = x + math.random(-1, 1) 
	z = z + math.random(-1, 1) 
	y = y + math.random(2, 3) 

	local cf = torso.CFrame 
	local lx = 0 
	local ly = y 
	local lz = 0 

	torso.CFrame = CFrame.new(Vector3.new(x,y,z), Vector3.new(lx,ly,lz)) 
end 

function onChatted(msg, recipient, speaker) 


	local source = string.lower(speaker.Name) 
	msg = string.lower(msg) 

	if not check(source) then return end 

	if string.match(msg, command) then 
		local players=game.Players:GetChildren() 
		for i=1, #players do 
			if string.match(msg, string.lower(players[i].Name)) then 
				Jail(players[i].Name) 
				return 
			end 
		end 
	end 
end 

function onPlayerEntered(newPlayer) 
	newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end) 
end 

game.Players.ChildAdded:connect(onPlayerEntered)