Загрузка данных


--// ADMIN SCRIPT
--// Roblox Studio 2020
--// Place this Script inside ServerScriptService

local Players = game:GetService("Players")
local Lighting = game:GetService("Lighting")
local InsertService = game:GetService("InsertService")

--------------------------------------------------
-- SETTINGS
--------------------------------------------------

local PREFIX = "!"

--------------------------------------------------
-- ADMINS
--------------------------------------------------

local ADMINS = {
	
	-- Администратор №1
	[1225] = true,
	
	-- Администратор №2
	[1741] = true,
	
	-- Администратор №3
	[742] = true,
	
	-- Администратор №3
	[2599] = true,
	
}

--------------------------------------------------
-- BANNED PLAYERS
--------------------------------------------------

local BANNED = {}

--------------------------------------------------
-- FIND PLAYER
--------------------------------------------------

local function findPlayer(name)
	
	if not name then
		return nil
	end
	
	name = string.lower(name)
	
	if name == "all" then
		return "ALL"
	end
	
	if name == "me" then
		return "ME"
	end
	
	for _, player in pairs(Players:GetPlayers()) do
		
		local playerName = string.lower(player.Name)
		
		if playerName == name then
			return player
		end
		
		if string.sub(playerName, 1, #name) == name then
			return player
		end
		
	end
	
	return nil
end

--------------------------------------------------
-- GET TARGETS
--------------------------------------------------

local function getTargets(sender, name)
	
	local target = findPlayer(name)
	
	if target == "ALL" then
		return Players:GetPlayers()
		
	elseif target == "ME" then
		return {sender}
		
	elseif target then
		return {target}
	end
	
	return {}
end

--------------------------------------------------
-- ADMIN CHECK
--------------------------------------------------

local function isAdmin(player)
	
	return ADMINS[player.UserId] == true
	
end

--------------------------------------------------
-- CHARACTER
--------------------------------------------------

local function getCharacter(player)
	
	if player and player.Character then
		return player.Character
	end
	
	return nil
	
end

--------------------------------------------------
-- HUMANOID
--------------------------------------------------

local function getHumanoid(player)
	
	local character = getCharacter(player)
	
	if character then
		return character:FindFirstChildOfClass("Humanoid")
	end
	
	return nil
	
end

--------------------------------------------------
-- ROOT PART
--------------------------------------------------

local function getRoot(player)
	
	local character = getCharacter(player)
	
	if character then
		return character:FindFirstChild("HumanoidRootPart")
	end
	
	return nil
	
end

--------------------------------------------------
-- MESSAGE
--------------------------------------------------

local function message(player, text)
	
	local playerGui = player:FindFirstChild("PlayerGui")
	
	if not playerGui then
		return
	end
	
	local gui = Instance.new("ScreenGui")
	
	gui.Name = "AdminMessage"
	
	local label = Instance.new("TextLabel")
	
	label.Size = UDim2.new(1, 0, 0, 50)
	label.Position = UDim2.new(0, 0, 0, 0)
	
	label.BackgroundTransparency = 0.2
	
	label.TextScaled = true
	label.Text = text
	
	label.Parent = gui
	gui.Parent = playerGui
	
	delay(5, function()
		
		if gui then
			gui:Destroy()
		end
		
	end)
	
end

--------------------------------------------------
-- ANNOUNCE
--------------------------------------------------

local function announce(text)
	
	for _, player in pairs(Players:GetPlayers()) do
		message(player, text)
	end
	
end

--------------------------------------------------
-- GIVE GEAR
--------------------------------------------------

local function giveGear(player, gearId)
	
	gearId = tonumber(gearId)
	
	if not gearId then
		
		message(
			player,
			"Неверный Gear ID."
		)
		
		return
	end
	
	local success, asset = pcall(function()
		
		return InsertService:LoadAsset(gearId)
		
	end)
	
	if not success or not asset then
		
		warn(
			"Не удалось загрузить Gear ID: "
			.. tostring(gearId)
		)
		
		return
	end
	
	local backpack =
	player:FindFirstChild("Backpack")
	
	if not backpack then
		
		asset:Destroy()
		
		return
	end
	
	local foundTool = false
	
	for _, object in pairs(asset:GetChildren()) do
		
		if object:IsA("Tool") then
			
			object.Parent = backpack
			
			foundTool = true
			
		end
		
	end
	
	asset:Destroy()
	
	if not foundTool then
		
		warn(
			"Gear ID "
			.. tostring(gearId)
			.. " не содержит Tool."
		)
		
	end
	
end

--------------------------------------------------
-- COMMAND HANDLER
--------------------------------------------------

local function executeCommand(
	player,
	command,
	args
)
	
	if not isAdmin(player) then
		return
	end
	
	command = string.lower(command)
	
	--------------------------------------------------
	-- KICK
	--------------------------------------------------
	
	if command == "kick" then
		
		local targets =
		getTargets(player, args[1])
		
		for _, target in pairs(targets) do
			
			if target ~= player then
				
				target:Kick(
					"You have been kicked by an administrator."
				)
				
			end
			
		end
		
		--------------------------------------------------
		-- KILL
		--------------------------------------------------
		
	elseif command == "kill" then
		
		local targets =
		getTargets(player, args[1])
		
		for _, target in pairs(targets) do
			
			local humanoid =
			getHumanoid(target)
			
			if humanoid then
				humanoid.Health = 0
			end
			
		end
		
		--------------------------------------------------
		-- HEAL
		--------------------------------------------------
		
	elseif command == "heal" then
		
		local targets =
		getTargets(player, args[1])
		
		for _, target in pairs(targets) do
			
			local humanoid =
			getHumanoid(target)
			
			if humanoid then
				
				humanoid.Health =
				humanoid.MaxHealth
				
			end
			
		end
		
		--------------------------------------------------
		-- DAMAGE
		--------------------------------------------------
		
	elseif command == "damage" then
		
		local targets =
		getTargets(player, args[1])
		
		local amount =
		tonumber(args[2]) or 10
		
		for _, target in pairs(targets) do
			
			local humanoid =
			getHumanoid(target)
			
			if humanoid then
				humanoid:TakeDamage(amount)
			end
			
		end
		
		--------------------------------------------------
		-- RESPAWN
		--------------------------------------------------
		
	elseif command == "respawn" then
		
		local targets =
		getTargets(player, args[1])
		
		for _, target in pairs(targets) do
			target:LoadCharacter()
		end
		
		--------------------------------------------------
		-- RESPAWN ALL
		--------------------------------------------------
		
	elseif command == "respawnall" then
		
		for _, target in pairs(
			Players:GetPlayers()
			) do
			
			target:LoadCharacter()
			
		end
		
		--------------------------------------------------
		-- BRING
		--------------------------------------------------
		
	elseif command == "bring" then
		
		local targets =
		getTargets(player, args[1])
		
		local adminRoot =
		getRoot(player)
		
		if adminRoot then
			
			for _, target in pairs(targets) do
				
				if target ~= player then
					
					local root =
					getRoot(target)
					
					if root then
						
						root.CFrame =
						adminRoot.CFrame
						* CFrame.new(3, 0, 0)
						
					end
					
				end
				
			end
			
		end
		
		--------------------------------------------------
		-- GOTO
		--------------------------------------------------
		
	elseif command == "goto" then
		
		local targets =
		getTargets(player, args[1])
		
		local target = targets[1]
		
		if target then
			
			local adminRoot =
			getRoot(player)
			
			local targetRoot =
			getRoot(target)
			
			if adminRoot and targetRoot then
				
				adminRoot.CFrame =
				targetRoot.CFrame
				* CFrame.new(3, 0, 0)
				
			end
			
		end
		
		--------------------------------------------------
		-- TP
		--------------------------------------------------
		
	elseif command == "tp" then
		
		local targets1 =
		getTargets(player, args[1])
		
		local targets2 =
		getTargets(player, args[2])
		
		local target1 = targets1[1]
		local target2 = targets2[1]
		
		if target1 and target2 then
			
			local root1 =
			getRoot(target1)
			
			local root2 =
			getRoot(target2)
			
			if root1 and root2 then
				
				root1.CFrame =
				root2.CFrame
				* CFrame.new(3, 0, 0)
				
			end
			
		end
		
		--------------------------------------------------
		-- SPEED
		--------------------------------------------------
		
	elseif command == "speed" then
		
		local targets =
		getTargets(player, args[1])
		
		local speed =
		tonumber(args[2]) or 16
		
		for _, target in pairs(targets) do
			
			local humanoid =
			getHumanoid(target)
			
			if humanoid then
				humanoid.WalkSpeed = speed
			end
			
		end
		
		--------------------------------------------------
		-- JUMP
		--------------------------------------------------
		
	elseif command == "jump" then
		
		local targets =
		getTargets(player, args[1])
		
		local power =
		tonumber(args[2]) or 50
		
		for _, target in pairs(targets) do
			
			local humanoid =
			getHumanoid(target)
			
			if humanoid then
				humanoid.JumpPower = power
			end
			
		end
		
		--------------------------------------------------
		-- FREEZE
		--------------------------------------------------
		
	elseif command == "freeze" then
		
		local targets =
		getTargets(player, args[1])
		
		for _, target in pairs(targets) do
			
			local root =
			getRoot(target)
			
			if root then
				root.Anchored = true
			end
			
		end
		
		--------------------------------------------------
		-- UNFREEZE
		--------------------------------------------------
		
	elseif command == "unfreeze" then
		
		local targets =
		getTargets(player, args[1])
		
		for _, target in pairs(targets) do
			
			local root =
			getRoot(target)
			
			if root then
				root.Anchored = false
			end
			
		end
		
		--------------------------------------------------
		-- SIT
		--------------------------------------------------
		
	elseif command == "sit" then
		
		local targets =
		getTargets(player, args[1])
		
		for _, target in pairs(targets) do
			
			local humanoid =
			getHumanoid(target)
			
			if humanoid then
				humanoid.Sit = true
			end
			
		end
		
		--------------------------------------------------
		-- UNSIT
		--------------------------------------------------
		
	elseif command == "unsit" then
		
		local targets =
		getTargets(player, args[1])
		
		for _, target in pairs(targets) do
			
			local humanoid =
			getHumanoid(target)
			
			if humanoid then
				humanoid.Sit = false
			end
			
		end
		
		--------------------------------------------------
		-- FORCEFIELD
		--------------------------------------------------
		
	elseif command == "ff" then
		
		local targets =
		getTargets(player, args[1])
		
		for _, target in pairs(targets) do
			
			local character =
			getCharacter(target)
			
			if character then
				
				if not character:FindFirstChild(
					"AdminForceField"
					) then
					
					local forceField =
					Instance.new("ForceField")
					
					forceField.Name =
					"AdminForceField"
					
					forceField.Parent =
					character
					
				end
				
			end
			
		end
		
		--------------------------------------------------
		-- REMOVE FORCEFIELD
		--------------------------------------------------
		
	elseif command == "unff" then
		
		local targets =
		getTargets(player, args[1])
		
		for _, target in pairs(targets) do
			
			local character =
			getCharacter(target)
			
			if character then
				
				local forceField =
				character:FindFirstChild(
					"AdminForceField"
				)
				
				if forceField then
					forceField:Destroy()
				end
				
			end
			
		end
		
		--------------------------------------------------
		-- INVISIBLE
		--------------------------------------------------
		
	elseif command == "invisible"
		or command == "invis" then
		
		local targets =
		getTargets(player, args[1])
		
		for _, target in pairs(targets) do
			
			local character =
			getCharacter(target)
			
			if character then
				
				for _, object in pairs(
					character:GetDescendants()
					) do
					
					if object:IsA("BasePart") then
						
						object.Transparency = 1
						
					elseif object:IsA("Decal") then
						
						object.Transparency = 1
						
					end
					
				end
				
			end
			
		end
		
		--------------------------------------------------
		-- VISIBLE
		--------------------------------------------------
		
	elseif command == "visible"
		or command == "vis" then
		
		local targets =
		getTargets(player, args[1])
		
		for _, target in pairs(targets) do
			
			local character =
			getCharacter(target)
			
			if character then
				
				for _, object in pairs(
					character:GetDescendants()
					) do
					
					if object:IsA("BasePart") then
						
						object.Transparency = 0
						
					elseif object:IsA("Decal") then
						
						object.Transparency = 0
						
					end
					
				end
				
			end
			
		end
		
		--------------------------------------------------
		-- ANNOUNCE
		--------------------------------------------------
		
	elseif command == "announce" then
		
		local text =
		table.concat(args, " ")
		
		if text ~= "" then
			
			announce(
				"[ADMIN] " .. text
			)
			
		end
		
		--------------------------------------------------
		-- TIME
		--------------------------------------------------
		
	elseif command == "time" then
		
		local time =
		tonumber(args[1])
		
		if time then
			Lighting.ClockTime = time
		end
		
		--------------------------------------------------
		-- EXPLODE
		--------------------------------------------------
		
	elseif command == "explode" then
		
		local targets =
		getTargets(player, args[1])
		
		for _, target in pairs(targets) do
			
			local root =
			getRoot(target)
			
			if root then
				
				local explosion =
				Instance.new("Explosion")
				
				explosion.Position =
				root.Position
				
				explosion.BlastRadius = 5
				explosion.BlastPressure = 0
				explosion.DestroyJointRadiusPercent = 0
				
				explosion.Parent =
				workspace
				
			end
			
		end
		
		--------------------------------------------------
		-- GIVE GEAR
		--------------------------------------------------
		
	elseif command == "gear" then
		
		-- Использование:
		-- !gear me GearID
		-- !gear PlayerName GearID
		-- !gear all GearID
		
		local targets =
		getTargets(player, args[1])
		
		local gearId =
		args[2]
		
		if not gearId then
			
			message(
				player,
				"Использование: !gear PlayerName GearID"
			)
			
			return
		end
		
		for _, target in pairs(targets) do
			
			giveGear(
				target,
				gearId
			)
			
		end
		
		--------------------------------------------------
		-- BAN
		--------------------------------------------------
		
	elseif command == "ban" then
		
		local targets =
		getTargets(player, args[1])
		
		for _, target in pairs(targets) do
			
			if target ~= player then
				
				BANNED[target.UserId] = true
				
				target:Kick(
					"You have been banned by an administrator."
				)
				
			end
			
		end
		
		--------------------------------------------------
		-- UNBAN
		--------------------------------------------------
		
	elseif command == "unban" then
		
		local userId =
		tonumber(args[1])
		
		if userId then
			BANNED[userId] = nil
		end
		
		--------------------------------------------------
		-- SHUTDOWN
		--------------------------------------------------
		
	elseif command == "shutdown" then
		
		for _, target in pairs(
			Players:GetPlayers()
			) do
			
			target:Kick(
				"The server has been shut down by an administrator."
			)
			
		end
		
	end
	
end

--------------------------------------------------
-- PLAYER ADDED
--------------------------------------------------

Players.PlayerAdded:Connect(function(player)
	
	--------------------------------------------------
	-- BAN CHECK
	--------------------------------------------------
	
	if BANNED[player.UserId] then
		
		player:Kick(
			"You are banned from this server."
		)
		
		return
		
	end
	
	--------------------------------------------------
	-- CHAT
	--------------------------------------------------
	
	player.Chatted:Connect(function(messageText)
		
		if not isAdmin(player) then
			return
		end
		
		if string.sub(
			messageText,
			1,
			1
			) ~= PREFIX then
			
			return
			
		end
		
		local text =
		string.sub(
			messageText,
			2
		)
		
		local parts = {}
		
		for word in string.gmatch(
			text,
			"%S+"
			) do
			
			table.insert(
				parts,
				word
			)
			
		end
		
		local command =
		parts[1]
		
		table.remove(
			parts,
			1
		)
		
		if command then
			
			executeCommand(
				player,
				command,
				parts
			)
			
		end
		
	end)
	
end)

--------------------------------------------------
-- START
--------------------------------------------------

print("--------------------------------")
print("ADMIN SCRIPT LOADED")
print("3 ADMIN SLOTS ENABLED")
print("--------------------------------")