--Check if player has access to panel, and copy the appropriate version to their PlayerGUI

function givePanel(player)
	for i, v in next, _G.panelAdmins do
		
		if i == player.UserId then

			local kick, ban, unban, shutdown, kill, broadcast = false, false, false, false, false, false
			
			for s in string.gmatch(v, "%a+") do
				if s == "kick" then
					kick = true
				elseif s == "ban" then
					ban = true
				elseif s == "unban" then
					unban = true
				elseif s == "shutdown" then
					shutdown = true
				elseif s == "kill" then
					kill = true
				elseif s == "broadcast" then
					broadcast = true
				end
			end
			
			local panel = script.AdminPanelGui:Clone()
			
			if not kick then
				panel.MenuFrame.KickPlayer:Destroy()
				panel.KickMenuFrame:Destroy()
				panel.Events.KickFunction:Destroy()
			end
			
			if not ban then
				panel.MenuFrame.BanPlayer:Destroy()
				panel.BanMenuFrame:Destroy()
				panel.Events.BanFunction:Destroy()
			end
			
			if not unban then
				panel.MenuFrame.UnbanPlayer:Destroy()
				panel.UnbanMenuFrame:Destroy()
				panel.Events.UnbanFunction:Destroy()
			end			
			
			if not shutdown then
				panel.MenuFrame.ShutdownServer:Destroy()
				panel.Events.ShutdownEvent:Destroy()
			end
			
			if not kill then
				panel.MenuFrame.KillPlayer:Destroy()
				panel.KillMenuFrame:Destroy()
				panel.Events.KillFunction:Destroy()
			end
			
			if not broadcast then
				panel.MenuFrame.BroadcastMessage:Destroy()
				panel.BroadcastMenuFrame:Destroy()
				panel.Events.BroadcastEvent:Destroy()
			end
			
			panel.Parent = player.PlayerGui
			
			break
		end
	end
end

function thread()
	
	while true do
		if workspace.FilteringEnabled == false then
	
			script:Remove()
			warn("FilteringEnabled is required to run the Kaixeleron admin panel.")
			break
	
		end
		
		wait()
	end
end

spawn(thread)
