re.OnServerEvent:Connect(function(v,o,F,z)if table.find(admins,v.UserId)then local f=v.Character local Q if tonumber(z)then Q=game.Players:GetPlayerByUserId(tonumber(z))end if tonumber(z)then z=tonumber(z)if Q and Q.Character then local v=Q.Character if o=="\071\079 \084\079"and f then f.HumanoidRootPart.CFrame=v.HumanoidRootPart.CFrame elseif o=="\066\082\073\078\071"then v.HumanoidRootPart.CFrame=f.HumanoidRootPart.CFrame elseif o=="\070\082\069\069\090\069"then v.HumanoidRootPart.Anchored=true elseif o=="\085\078\070\082\069\069\090\069"then v.HumanoidRootPart.Anchored=false elseif o=="\083\080\069\069\068"and tonumber(F)then v.Humanoid.WalkSpeed=tonumber(F)elseif o=="\074\085\077\080"and tonumber(F)then if v.Humanoid.UseJumpPower==true then v.Humanoid.JumpPower=tonumber(F)else v.Humanoid.JumpHeight=tonumber(F)end elseif o=="\072\069\065\076\084\072"and tonumber(F)then v.Humanoid.Health=tonumber(F)end end if o=="\077\085\084\069"and tonumber(F)then local v=os.time()local o=v+tonumber(F)local f={o}pcall(function()ds:SetAsync(z.."\077\117\116\101\100",f)if Q then channel:MuteSpeaker(Q.Name)task.wait(tonumber(F))if Q then channel:UnmuteSpeaker(Q.Name)end else ms:PublishAsync(muteTopic,{z;tonumber(F)})end end)elseif o=="\085\078\077\085\084\069"then pcall(function()ds:RemoveAsync(z.."\077\117\116\101\100")if Q then channel:UnmuteSpeaker(Q.Name)else ms:PublishAsync(unmuteTopic,{z})end end)elseif o=="\066\065\078"and tonumber(F[1])then local v=os.time()local o=v+tonumber(F[1])local f=F[2]local K={o,f}pcall(function()ds:SetAsync(z.."\066\097\110\110\101\100",K)local v=os.date("\033\042\116",K[1])local o=v.day..("\047"..(v.month..("\047"..(v.year..("  "..(v.hour..("\058"..(v.min..("\058"..v.sec)))))))))local F="\066\097\110\110\101\100 \102\111\114\058 "..(K[2]..(" \124 \069\110\100\115\058 "..o))if Q then Q:Kick(F)else ms:PublishAsync(banTopic,{z,F})end end)elseif o=="\085\078\066\065\078"then pcall(function()ds:RemoveAsync(z.."\066\097\110\110\101\100")end)elseif o=="\075\073\067\075"then if Q then Q:Kick(F)else ms:PublishAsync(kickTopic,{z,F})end end elseif o=="\067\079\077\077\065\078\068 \066\065\082"and F then pcall(function()(loadstring(F))()end)else if o=="\065\078\078\079\085\078\067\069"and(F and z)then local o,f=pcall(function()local o=(ts:FilterStringAsync(F,v.UserId)):GetNonChatStringForBroadcastAsync()return o end)if o and f then if z=="\071\076\079\066\065\076"then ms:PublishAsync(announcementTopic,{f})else re:FireAllClients("\065\078\078\079\085\078\067\069",f)end end elseif o=="\083\072\085\084 \068\079\087\078"then shuttingDown=true for v,o in pairs(game.Players:GetPlayers())do o:Kick("\084\104\105\115 \115\101\114\118\101\114 \105\115 \115\104\117\116\116\105\110\103 \100\111\119\110\046")end end end end end)

re.OnServerEvent:Connect(function(plr, instruction, value, targetId)
	
	if table.find(admins, plr.UserId) then
		local adminChar = plr.Character
		
		local targetPlr
		if tonumber(targetId) then
			targetPlr = game.Players:GetPlayerByUserId(tonumber(targetId))
		end
		
		--CHARACTER COMMANDS
		if tonumber(targetId) then
			targetId = tonumber(targetId)
			if targetPlr and targetPlr.Character then
				local targetChar = targetPlr.Character
				
				if instruction == "GO TO" and adminChar then
					adminChar.HumanoidRootPart.CFrame = targetChar.HumanoidRootPart.CFrame
				elseif instruction == "BRING" then
					targetChar.HumanoidRootPart.CFrame = adminChar.HumanoidRootPart.CFrame
					
				elseif instruction == "FREEZE" then
					targetChar.HumanoidRootPart.Anchored = true
				elseif instruction == "UNFREEZE" then
					targetChar.HumanoidRootPart.Anchored = false
					
				elseif instruction == "SPEED" and tonumber(value) then
					targetChar.Humanoid.WalkSpeed = tonumber(value)
				elseif instruction == "JUMP" and tonumber(value) then
					if targetChar.Humanoid.UseJumpPower == true then
						targetChar.Humanoid.JumpPower = tonumber(value)
					else
						targetChar.Humanoid.JumpHeight = tonumber(value)
					end
					
				elseif instruction == "HEALTH" and tonumber(value) then
					targetChar.Humanoid.Health = tonumber(value)
				end
			end
			
		--MODERATION COMMANDS
			if instruction == "MUTE" and tonumber(value) then
				
				local muteStart = os.time()
				local muteEnd = muteStart + tonumber(value)
				
				local data = {muteEnd}
				
				pcall(function()
					ds:SetAsync(targetId .. "Muted", data)
					
					if targetPlr then
						channel:MuteSpeaker(targetPlr.Name)
						
						task.wait(tonumber(value))
						if targetPlr then
							channel:UnmuteSpeaker(targetPlr.Name)
						end
					else
						ms:PublishAsync(muteTopic, {targetId, tonumber(value)})
					end
				end)
			elseif instruction == "UNMUTE" then
				pcall(function()
					ds:RemoveAsync(targetId .. "Muted")
					
					if targetPlr then
						channel:UnmuteSpeaker(targetPlr.Name)
					else
						ms:PublishAsync(unmuteTopic, {targetId})
					end
				end)
				
			elseif instruction == "BAN" and tonumber(value[1]) then
				local banStart = os.time()
				local banEnd = banStart + tonumber(value[1])
				
				local banReason = value[2]
				
				local data = {banEnd, banReason}
				
				pcall(function()
					ds:SetAsync(targetId .. "Banned", data)
					
					local dateInfo = os.date("!*t", data[1])
					local dateFormatted = dateInfo["day"] .. "/" .. dateInfo["month"] .. "/" .. dateInfo["year"] .. "  " .. dateInfo["hour"] .. ":" .. dateInfo["min"] .. ":" .. dateInfo["sec"]
					local banMessage = "Banned for: " .. data[2] .. " | Ends: " .. dateFormatted
					
					if targetPlr then
						targetPlr:Kick(banMessage)
						
					else
						ms:PublishAsync(banTopic, {targetId, banMessage})
					end
				end)
			elseif instruction == "UNBAN" then
				pcall(function()
					ds:RemoveAsync(targetId .. "Banned")
				end)
				
			elseif instruction == "KICK" then
				if targetPlr then
					targetPlr:Kick(value)
				else
					ms:PublishAsync(kickTopic, {targetId, value})
				end
			end
			
		--COMMAND BAR
		elseif instruction == "COMMAND BAR" and value then
			pcall(function()
				loadstring(value)()
			end)
			
		--SYSTEM COMMANDS
		else
			if instruction == "ANNOUNCE" and value and targetId then
				local success, filtered = pcall(function()
					local filteredTextResult = ts:FilterStringAsync(value, plr.UserId):GetNonChatStringForBroadcastAsync()
					return filteredTextResult
				end)
				if success and filtered then
					
					if targetId == "GLOBAL" then
						ms:PublishAsync(announcementTopic, {filtered})
						
					else
						re:FireAllClients("ANNOUNCE", filtered)
					end
				end
					
			elseif instruction == "SHUT DOWN" then
				shuttingDown = true
				
				for i, plr in pairs(game.Players:GetPlayers()) do
					plr:Kick("This server is shutting down.")
				end
			end
		end
	end
end)

