-- Fly and Teleport Script for Roblox (Activate with /fly, /unfly, /tp, /looptp, /unlooptp commands) local UserInputService = game:GetService("UserInputService") local Player = game.Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded:Wait() local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart") local Camera = workspace.CurrentCamera local Mouse = Player:GetMouse() local flying = false local speed = 50 local bodyVelocity local bodyGyro local movementDirection = Vector3.new(0, 0, 0) local teleportLooping = false local teleportLoopPlayer = nil local teleportLoopInterval = 0.00000001 -- Interval set to 0.00000001 seconds (extremely fast) -- Function to enable Shift Lock local function enableShiftLock() UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter UserInputService.MouseIconEnabled = false end -- Function to disable Shift Lock local function disableShiftLock() UserInputService.MouseBehavior = Enum.MouseBehavior.Default UserInputService.MouseIconEnabled = true end -- Function to start flying local function startFlying() if flying then return end flying = true -- Enable Shift Lock enableShiftLock() -- Create BodyVelocity and BodyGyro for flight control bodyVelocity = Instance.new("BodyVelocity") bodyGyro = Instance.new("BodyGyro") bodyVelocity.MaxForce = Vector3.new(100000, 100000, 100000) bodyVelocity.Velocity = Vector3.new(0, 0, 0) bodyVelocity.Parent = Character:WaitForChild("HumanoidRootPart") bodyGyro.MaxTorque = Vector3.new(400000, 400000, 400000) bodyGyro.CFrame = Character:WaitForChild("HumanoidRootPart").CFrame bodyGyro.Parent = Character:WaitForChild("HumanoidRootPart") -- Disable default gravity Character.Humanoid.PlatformStand = true end -- Function to stop flying local function stopFlying() if not flying then return end flying = false -- Disable Shift Lock disableShiftLock() -- Remove BodyVelocity and BodyGyro if bodyVelocity then bodyVelocity:Destroy() end if bodyGyro then bodyGyro:Destroy() end -- Re-enable gravity Character.Humanoid.PlatformStand = false end -- Function to handle teleportation to a player's head by display name local function teleportToPlayerHeadByDisplayName(displayName) for _, targetPlayer in pairs(game.Players:GetPlayers()) do if targetPlayer.DisplayName:lower() == displayName:lower() then if targetPlayer.Character and targetPlayer.Character:FindFirstChild("Head") then local targetHead = targetPlayer.Character.Head -- Teleport to the target player's head position Character:SetPrimaryPartCFrame(targetHead.CFrame) return end end end -- If no player with the given display name is found Player:Chat("Player with display name '" .. displayName .. "' not found!") end -- Function to teleport to a random player's head local function teleportToRandomPlayerHead() local players = game.Players:GetPlayers() -- Remove the local player from the list so we don't teleport to ourselves local otherPlayers = {} for _, targetPlayer in pairs(players) do if targetPlayer ~= Player then table.insert(otherPlayers, targetPlayer) end end -- If there are any other players, teleport to a random one if #otherPlayers > 0 then local randomPlayer = otherPlayers[math.random(1, #otherPlayers)] if randomPlayer.Character and randomPlayer.Character:FindFirstChild("Head") then local targetHead = randomPlayer.Character.Head -- Teleport to the random player's head position Character:SetPrimaryPartCFrame(targetHead.CFrame) return randomPlayer -- Return the chosen random player for the loop end else Player:Chat("No other players in the game to teleport to!") end end -- Function to start looping teleportation to a player's head by display name local function startLoopTeleportToHead(displayName) if teleportLooping then return end teleportLooping = true teleportLoopPlayer = displayName while teleportLooping do teleportToPlayerHeadByDisplayName(teleportLoopPlayer) wait(teleportLoopInterval) -- Wait for the specified interval before teleporting again end end -- Function to start looping teleportation to a random player's head local function startLoopTeleportToRandomHead() if teleportLooping then return end teleportLooping = true -- Choose a random player once local selectedPlayer = teleportToRandomPlayerHead() if selectedPlayer then while teleportLooping do -- Keep teleporting to the same selected player's head if selectedPlayer.Character and selectedPlayer.Character:FindFirstChild("Head") then local targetHead = selectedPlayer.Character.Head -- Teleport to the same random player's head in the loop Character:SetPrimaryPartCFrame(targetHead.CFrame) end wait(teleportLoopInterval) -- Wait for the specified interval before teleporting again end end end -- Function to stop looping teleportation local function stopLoopTeleport() teleportLooping = false teleportLoopPlayer = nil end -- Function to list all commands local function printCommands() -- List all available commands Player:Chat("Available Commands:") Player:Chat("/fly - Start flying") Player:Chat("/unfly - Stop flying") Player:Chat("/tp [DisplayName] - Teleport to a player's head by display name") Player:Chat("/tp random - Teleport to a random player's head") Player:Chat("/looptp [DisplayName] - Start looping teleportation to a player's head") Player:Chat("/looptp random - Start looping teleportation to a random player's head") Player:Chat("/unlooptp - Stop the teleportation loop") Player:Chat("/cmds - List all available commands") end -- Listen for /fly, /unfly, /tp, /looptp, /unlooptp, /stoploop, and /cmds commands in chat Player.Chatted:Connect(function(message) -- Check for /fly command if message:lower() == "/fly" then if not flying then startFlying() -- Start flying else print("You are already flying!") end -- Check for /unfly command elseif message:lower() == "/unfly" then if flying then stopFlying() -- Stop flying else print("You are not flying!") end -- Check for /tp [DisplayName] command elseif message:lower():sub(1, 3) == "/tp" then local argument = message:sub(5) -- Remove "/tp " from the message if argument == "random" then -- Teleport to a random player's head teleportToRandomPlayerHead() elseif argument and argument ~= "" then -- Teleport to the player with the given display name teleportToPlayerHeadByDisplayName(argument) else Player:Chat("Please specify a player display name or 'random' after /tp!") end -- Check for /looptp [DisplayName] command elseif message:lower():sub(1, 7) == "/looptp" then local argument = message:sub(9) -- Remove "/looptp " from the message if argument == "random" then -- Start teleporting to a random player's head in a loop startLoopTeleportToRandomHead() elseif argument and argument ~= "" then -- Start teleporting to the specified player's head in a loop startLoopTeleportToHead(argument) else Player:Chat("Please specify a player display name or 'random' after /looptp!") end -- Check for /unlooptp command to stop the teleport loop elseif message:lower() == "/unlooptp" then -- Stop the loop if it's running stopLoopTeleport() -- Check for /cmds command to list all available commands elseif message:lower() == "/cmds" then printCommands() -- Print all commands in chat end end) -- Update flight control based on player input game:GetService("RunService").RenderStepped:Connect(function(_, dt) if flying then -- Get the direction the player is looking (forward and right vectors) local lookDirection = Character:WaitForChild("HumanoidRootPart").CFrame.LookVector local rightDirection = Character:WaitForChild("HumanoidRootPart").CFrame.RightVector -- Check for movement direction based on the keys pressed movementDirection = Vector3.new(0, 0, 0) if UserInputService:IsKeyDown(Enum.KeyCode.W) then -- Move forward based on where the player is looking movementDirection = movementDirection + lookDirection end if UserInputService:IsKeyDown(Enum.KeyCode.S) then -- Move backward based on where the player is looking movementDirection = movementDirection - lookDirection end if UserInputService:IsKeyDown(Enum.KeyCode.A) then -- Move left based on where the player is looking movementDirection = movementDirection - rightDirection end if UserInputService:IsKeyDown(Enum.KeyCode.D) then -- Move right based on where the player is looking movementDirection = movementDirection + rightDirection end -- Normalize the direction to avoid faster diagonal movement if movementDirection.magnitude > 0 then movementDirection = movementDirection.unit end -- Apply the movement direction and speed to the body velocity bodyVelocity.Velocity = movementDirection * speed bodyGyro.CFrame = CFrame.new(Character:WaitForChild("HumanoidRootPart").Position, Mouse.Hit.p) end end)