--If admin, give access to admin panel


else
	--Alert user they are an admin
	createAnnouncement("You are an admin.\nUse the 'B' key to open the admin panel.")
	
	uis.InputBegan:Connect(function(inp, p)
		if not p and inp.KeyCode == Enum.KeyCode.B then --Press B on keyboard to open admin panel
			panel.Visible = not panel.Visible
		end
	end)
	
	panel.CloseButton.MouseButton1Click:Connect(function() --Close admin panel when button is clicked on
		panel.Visible = false
	end)
	
	selectPlrFrame.UserIdBox.FocusLost:Connect(function() --Search UserIds to select players not in the same server as the admin
		local userId = selectPlrFrame.UserIdBox.Text
		
		if tonumber(userId) then
			local plrInfo = game:GetService("UserService"):GetUserInfosByUserIdsAsync({tonumber(userId)})[1]
			if plrInfo then
				local username = plrInfo.Username
				local displayName = plrInfo.DisplayName
				local inServer = game.Players:FindFirstChild(username)
				local image = game.Players:GetUserThumbnailAsync(userId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100)
				
				selectedFrame.PlayerName.Text = username
				selectedFrame.DisplayName.Text = "@" .. displayName
				selectedFrame.UserId.Text = userId
				selectedFrame.InGame.Text = inServer and "Currently in server 🟢" or "Not in server 🔴"
				selectedFrame.PlayerImage.Image = image

				selectedFrame.Visible = true
			end
		end
	end)
	
	--Command Bar
	panel.CommandBar.FocusLost:Connect(function(enterPressed)
		if enterPressed then
			re:FireServer("COMMAND BAR", panel.CommandBar.Text)
		end
	end)
	
	local btns = panel.Pages.MainButtonsFrame.ButtonsScroller; btns.Parent.Visible = true
	local muteFrame = panel.Pages.MuteFrame; muteFrame.Visible = false
	local banFrame = panel.Pages.BanFrame; banFrame.Visible = false
	local kickFrame = panel.Pages.KickFrame; kickFrame.Visible = false
	local annFrame = panel.Pages.AnnounceFrame; annFrame.Visible = false
	local shutFrame = panel.Pages.ShutdownFrame; shutFrame.Visible = false
	
	--MODERATION BUTTONS
	--Mute Button
	btns.ModerationButtons.MuteButton.MouseButton1Click:Connect(function()
		if tonumber(selectedFrame.UserId.Text) then
			muteFrame.DisplayName.Text = selectedFrame.DisplayName.Text
			muteFrame.PlayerName.Text = selectedFrame.PlayerName.Text
			muteFrame.PlayerImage.Image = selectedFrame.PlayerImage.Image
			muteFrame.Visible = true
			btns.Parent.Visible = false
		end
	end)
	muteFrame.BackButton.MouseButton1Click:Connect(function()
		btns.Parent.Visible = true
		muteFrame.Visible = false
	end)
	muteFrame.ConfirmButton.MouseButton1Click:Connect(function()
		local name = string.gsub(muteFrame.PlayerName.Text, "@", "")
		local targetId = game.Players:GetUserIdFromNameAsync(name)
		local length = tonumber(muteFrame.MuteLengthBox.Text)
		if targetId and length then
			btns.Parent.Visible = true
			muteFrame.Visible = false
			re:FireServer("MUTE", length, targetId)
		end
	end)
	
	--Unmute Button
	btns.ModerationButtons.UnmuteButton.MouseButton1Click:Connect(function()
		if tonumber(selectedFrame.UserId.Text) then
			re:FireServer("UNMUTE", nil, tonumber(selectedFrame.UserId.Text))
		end
	end)
	--Ban Button
	btns.ModerationButtons.BanButton.MouseButton1Click:Connect(function()
		if tonumber(selectedFrame.UserId.Text) then
			banFrame.DisplayName.Text = selectedFrame.DisplayName.Text
			banFrame.PlayerName.Text = selectedFrame.PlayerName.Text
			banFrame.PlayerImage.Image = selectedFrame.PlayerImage.Image
			panel.Pages.BanFrame.Visible = true
			btns.Parent.Visible = false
		end
	end)
	banFrame.BackButton.MouseButton1Click:Connect(function()
		btns.Parent.Visible = true
		banFrame.Visible = false
	end)
	banFrame.ConfirmButton.MouseButton1Click:Connect(function()
		local name = string.gsub(banFrame.PlayerName.Text, "@", "")
		local targetId = game.Players:GetUserIdFromNameAsync(name)
		local length = tonumber(banFrame.BanLengthBox.Text)
		local compiled = {length, banFrame.ReasonBox.Text}
		if targetId and length then
			btns.Parent.Visible = true
			banFrame.Visible = false
			re:FireServer("BAN", compiled, targetId)
		end
	end)
	--Unban Button
	btns.ModerationButtons.UnbanButton.MouseButton1Click:Connect(function()
		if tonumber(selectedFrame.UserId.Text) then
			re:FireServer("UNBAN", nil, tonumber(selectedFrame.UserId.Text))
		end
	end)
	--Kick Button
	btns.ModerationButtons.KickButton.MouseButton1Click:Connect(function()
		if tonumber(selectedFrame.UserId.Text) then
			kickFrame.DisplayName.Text = selectedFrame.DisplayName.Text
			kickFrame.PlayerName.Text = selectedFrame.PlayerName.Text
			kickFrame.PlayerImage.Image = selectedFrame.PlayerImage.Image
			panel.Pages.KickFrame.Visible = true
			btns.Parent.Visible = false
		end
	end)
	kickFrame.BackButton.MouseButton1Click:Connect(function()
		btns.Parent.Visible = true
		kickFrame.Visible = false
	end)
	kickFrame.ConfirmButton.MouseButton1Click:Connect(function()
		local name = string.gsub(kickFrame.PlayerName.Text, "@", "")
		local targetId = game.Players:GetUserIdFromNameAsync(name)
		local reason = kickFrame.ReasonBox.Text
		if targetId then
			btns.Parent.Visible = true
			kickFrame.Visible = false
			re:FireServer("KICK", reason, targetId)
		end
	end)
	
	--CHARACTER BUTTONS
	--Go To Button
	btns.CharacterButtons.GoToButton.MouseButton1Click:Connect(function()
		if tonumber(selectedFrame.UserId.Text) then
			re:FireServer("GO TO", nil, tonumber(selectedFrame.UserId.Text))
		end
	end)
	--Bring Button
	btns.CharacterButtons.BringButton.MouseButton1Click:Connect(function()
		if tonumber(selectedFrame.UserId.Text) then
			re:FireServer("BRING", nil, tonumber(selectedFrame.UserId.Text))
		end
	end)
	--Freeze Button
	btns.CharacterButtons.FreezeButton.MouseButton1Click:Connect(function()
		if tonumber(selectedFrame.UserId.Text) then
			re:FireServer("FREEZE", nil, tonumber(selectedFrame.UserId.Text))
		end
	end)
	--Unfreeze Button
	btns.CharacterButtons.UnfreezeButton.MouseButton1Click:Connect(function()
		if tonumber(selectedFrame.UserId.Text) then
			re:FireServer("UNFREEZE", nil, tonumber(selectedFrame.UserId.Text))
		end
	end)
	--Speed Input Box
	btns.CharacterButtons.WalkSpeedBox.FocusLost:Connect(function(enterPressed)
		if enterPressed and tonumber(selectedFrame.UserId.Text) then
			re:FireServer("SPEED", tonumber(btns.CharacterButtons.WalkSpeedBox.Text), tonumber(selectedFrame.UserId.Text))
		end
	end)
	--Jump Input Box
	btns.CharacterButtons.JumpHeightBox.FocusLost:Connect(function(enterPressed)
		if enterPressed and tonumber(selectedFrame.UserId.Text) then
			re:FireServer("JUMP", tonumber(btns.CharacterButtons.JumpHeightBox.Text), tonumber(selectedFrame.UserId.Text))
		end
	end)
	--Health Input Box
	btns.CharacterButtons.HealthBox.FocusLost:Connect(function(enterPressed)
		if enterPressed and tonumber(selectedFrame.UserId.Text) then
			re:FireServer("HEALTH", tonumber(btns.CharacterButtons.HealthBox.Text), tonumber(selectedFrame.UserId.Text))
		end
	end)
	
	--SYSTEM BUTTONS
	--Announce Button
	btns.SystemButtons.AnnounceButton.MouseButton1Click:Connect(function()
		panel.Pages.AnnounceFrame.Visible = true
		btns.Parent.Visible = false
	end)
	annFrame.BackButton.MouseButton1Click:Connect(function()
		btns.Parent.Visible = true
		annFrame.Visible = false
	end)
	local server = annFrame.ServerButton
	local global = annFrame.GlobalButton
	server.CircleBackground.CircleFill.Visible = true
	server.MouseButton1Click:Connect(function()
		global.CircleBackground.CircleFill.Visible = false
		server.CircleBackground.CircleFill.Visible = true
	end)
	global.CircleBackground.CircleFill.Visible = false
	global.MouseButton1Click:Connect(function()
		server.CircleBackground.CircleFill.Visible = false
		global.CircleBackground.CircleFill.Visible = true
	end)
	annFrame.ConfirmButton.MouseButton1Click:Connect(function()
		local message = annFrame.AnnouncementBox.Text
		local messageGlobal = global.CircleBackground.CircleFill.Visible and "GLOBAL" or "SERVER"
		if string.len(message) > 0 then
			btns.Parent.Visible = true
			annFrame.Visible = false
			re:FireServer("ANNOUNCE", message, messageGlobal)
		end
	end)
	--Shutdown Button
	btns.SystemButtons.ShutdownButton.MouseButton1Click:Connect(function()
		panel.Pages.ShutdownFrame.Visible = true
		btns.Parent.Visible = false
	end)
	shutFrame.BackButton.MouseButton1Click:Connect(function()
		btns.Parent.Visible = true
		shutFrame.Visible = false
	end)
	shutFrame.ConfirmButton.MouseButton1Click:Connect(function()
		btns.Parent.Visible = true
		shutFrame.Visible = false
		re:FireServer("SHUT DOWN")
	end)
end