Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --// LocalScript inside StarterGui
- local Players = game:GetService("Players")
- local RunService = game:GetService("RunService")
- local UserInputService = game:GetService("UserInputService")
- local localPlayer = Players.LocalPlayer
- -- Gui
- local screenGui = Instance.new("ScreenGui")
- screenGui.Name = "ControlGui"
- screenGui.ResetOnSpawn = false
- screenGui.Parent = localPlayer:WaitForChild("PlayerGui")
- local frame = Instance.new("Frame")
- frame.Size = UDim2.new(0, 250, 0, 150)
- frame.Position = UDim2.new(0.05, 0, 0.2, 0)
- frame.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
- frame.BackgroundTransparency = 0.2
- frame.Parent = screenGui
- frame.Active = true
- frame.Draggable = true
- Instance.new("UICorner", frame).CornerRadius = UDim.new(0, 12)
- local textBox = Instance.new("TextBox")
- textBox.Size = UDim2.new(0.9, 0, 0, 30)
- textBox.Position = UDim2.new(0.05, 0, 0.1, 0)
- textBox.PlaceholderText = "Enter owner name"
- textBox.Text = ""
- textBox.BackgroundColor3 = Color3.new(1, 1, 1)
- textBox.TextColor3 = Color3.new(0, 0, 0)
- textBox.Parent = frame
- Instance.new("UICorner", textBox).CornerRadius = UDim.new(0, 8)
- local button = Instance.new("TextButton")
- button.Size = UDim2.new(0.9, 0, 0, 40)
- button.Position = UDim2.new(0.05, 0, 0.4, 0)
- button.Text = "Get Controlled"
- button.BackgroundColor3 = Color3.new(1, 1, 1)
- button.TextColor3 = Color3.new(0, 0, 0)
- button.Parent = frame
- Instance.new("UICorner", button).CornerRadius = UDim.new(0, 8)
- -- Vars
- local controller = nil
- local followConn = nil
- local flyConn = nil
- local spinConn = nil
- local flying = false
- local spinning = false
- local whitelist = {}
- -- Utility
- local function findPlayerByNameOrDisplay(input)
- for _, plr in ipairs(Players:GetPlayers()) do
- if plr.Name:lower() == input:lower() or plr.DisplayName:lower() == input:lower() then
- return plr
- end
- end
- return nil
- end
- -- Attach / Detach
- local function stopAttach()
- if followConn then
- followConn:Disconnect()
- followConn = nil
- end
- end
- local function startAttach(targetPlayer)
- stopAttach()
- local myChar = localPlayer.Character or localPlayer.CharacterAdded:Wait()
- local myRoot = myChar:WaitForChild("HumanoidRootPart")
- followConn = RunService.RenderStepped:Connect(function()
- local targetChar = targetPlayer.Character
- if targetChar and targetChar:FindFirstChild("HumanoidRootPart") and myChar.Parent then
- myRoot.CFrame = targetChar.HumanoidRootPart.CFrame * CFrame.new(0, 0, -3)
- else
- stopAttach()
- end
- end)
- end
- -- Fly
- local function startFly()
- if flying then return end
- flying = true
- local char = localPlayer.Character
- if not char then return end
- local hrp = char:WaitForChild("HumanoidRootPart")
- local hum = char:WaitForChild("Humanoid")
- hum.PlatformStand = true
- flyConn = RunService.RenderStepped:Connect(function()
- local moveDir = Vector3.zero
- if UserInputService:IsKeyDown(Enum.KeyCode.W) then moveDir += workspace.CurrentCamera.CFrame.LookVector end
- if UserInputService:IsKeyDown(Enum.KeyCode.S) then moveDir -= workspace.CurrentCamera.CFrame.LookVector end
- if UserInputService:IsKeyDown(Enum.KeyCode.A) then moveDir -= workspace.CurrentCamera.CFrame.RightVector end
- if UserInputService:IsKeyDown(Enum.KeyCode.D) then moveDir += workspace.CurrentCamera.CFrame.RightVector end
- if moveDir.Magnitude > 0 then
- hrp.Velocity = moveDir.Unit * 50
- else
- hrp.Velocity = Vector3.zero
- end
- end)
- end
- local function stopFly()
- if not flying then return end
- flying = false
- if flyConn then flyConn:Disconnect() flyConn = nil end
- local char = localPlayer.Character
- if char and char:FindFirstChild("Humanoid") then
- char.Humanoid.PlatformStand = false
- end
- end
- -- Spin
- local function startSpin()
- if spinning then return end
- spinning = true
- local char = localPlayer.Character
- if not char then return end
- local hrp = char:WaitForChild("HumanoidRootPart")
- spinConn = RunService.RenderStepped:Connect(function()
- if hrp.Parent then
- hrp.CFrame = hrp.CFrame * CFrame.Angles(0, math.rad(10), 0)
- else
- stopSpin()
- end
- end)
- end
- local function stopSpin()
- if not spinning then return end
- spinning = false
- if spinConn then spinConn:Disconnect() spinConn = nil end
- end
- -- Button
- button.MouseButton1Click:Connect(function()
- local name = textBox.Text
- local target = findPlayerByNameOrDisplay(name)
- if target then
- controller = target
- button.Text = "Controller set: " .. target.DisplayName
- else
- button.Text = "Player not found"
- end
- end)
- -- Commands
- local function handleCommand(player, msg)
- if player ~= controller and not whitelist[player.UserId] then return end
- msg = msg:lower()
- if msg == "!attach" and controller then
- startAttach(controller)
- elseif msg == "!detach" then
- stopAttach()
- elseif msg == "!reset" then
- local hum = localPlayer.Character and localPlayer.Character:FindFirstChildOfClass("Humanoid")
- if hum then hum.Health = 0 end
- elseif msg == "!spin" then
- startSpin()
- elseif msg == "!unspin" then
- stopSpin()
- elseif msg == "!fly" then
- startFly()
- elseif msg == "!unfly" then
- stopFly()
- elseif msg:sub(1,6) == "!give " then
- local targetName = msg:sub(7)
- local target = findPlayerByNameOrDisplay(targetName)
- if target then whitelist[target.UserId] = true end
- elseif msg:sub(1,8) == "!return " then
- local targetName = msg:sub(9)
- local target = findPlayerByNameOrDisplay(targetName)
- if target then whitelist[target.UserId] = nil end
- end
- end
- -- Connect chatted
- local function connectPlayer(plr)
- plr.Chatted:Connect(function(msg)
- handleCommand(plr, msg)
- end)
- end
- for _, plr in ipairs(Players:GetPlayers()) do
- connectPlayer(plr)
- end
- Players.PlayerAdded:Connect(connectPlayer)
Advertisement
Add Comment
Please, Sign In to add comment