Advertisement
Erktiky

Roblox Flying Part Script

Mar 21st, 2023
1,143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.05 KB | None | 0 0
  1. -------CREDITS--------------CREDITS--------------CREDITS--------------CREDITS-------
  2.  
  3. --[[
  4.  
  5.  
  6. ███╗░░░███╗░█████╗░██████╗░███████╗  ██████╗░██╗░░░██╗
  7. ████╗░████║██╔══██╗██╔══██╗██╔════╝  ██╔══██╗╚██╗░██╔╝
  8. ██╔████╔██║███████║██║░░██║█████╗░░  ██████╦╝░╚████╔╝░
  9. ██║╚██╔╝██║██╔══██║██║░░██║██╔══╝░░  ██╔══██╗░░╚██╔╝░░
  10. ██║░╚═╝░██║██║░░██║██████╔╝███████╗  ██████╦╝░░░██║░░░
  11. ╚═╝░░░░░╚═╝╚═╝░░╚═╝╚═════╝░╚══════╝  ╚═════╝░░░░╚═╝░░░
  12.  
  13. ███████╗██████╗░██╗░░██╗████████╗██╗██╗░░██╗██╗░░░██╗██╗
  14. ██╔════╝██╔══██╗██║░██╔╝╚══██╔══╝██║██║░██╔╝╚██╗░██╔╝██║
  15. █████╗░░██████╔╝█████═╝░░░░██║░░░██║█████═╝░░╚████╔╝░██║
  16. ██╔══╝░░██╔══██╗██╔═██╗░░░░██║░░░██║██╔═██╗░░░╚██╔╝░░╚═╝
  17. ███████╗██║░░██║██║░╚██╗░░░██║░░░██║██║░╚██╗░░░██║░░░██╗
  18. ╚══════╝╚═╝░░╚═╝╚═╝░░╚═╝░░░╚═╝░░░╚═╝╚═╝░░╚═╝░░░╚═╝░░░╚═╝
  19.  
  20.  
  21. --]]
  22.  
  23. -----TUTORIAL----------TUTORIAL----------TUTORIAL----------TUTORIAL-----
  24.  
  25. --[[
  26.  
  27. Once the part spawns, you need to touch the thin part in the middle of the base.
  28. Then your character will be locked and you will be able to control the part with WASD.
  29. You can also go up with E and go down with Q.
  30. Once you want to exit the seat press spacebar.
  31. You can also stand on the part, it's just transparent.
  32.  
  33. --]]
  34.  
  35. if game.Workspace:FindFirstChild(game.Players.LocalPlayer.Name) then
  36.     task.wait()
  37.     local UIS = game:GetService("UserInputService")
  38.     local part = Instance.new("Part")
  39.     part.Position = game.Players.LocalPlayer.Character.Head.Position - Vector3.new(0,3,0)
  40.     part.Anchored = true
  41.     part.Parent = workspace
  42.     part.Name = "FlyingPart"
  43.     part.Size = Vector3.new(10,1,10)
  44.     part.Material = Enum.Material.ForceField
  45.     part.FrontSurface = Enum.SurfaceType.Hinge
  46.  
  47.     local seat = Instance.new("Seat")
  48.     seat.Parent = part
  49.     seat.Size = Vector3.new(0.1,1.5,0.1)
  50.     seat.Position = part.Position + Vector3.new(0,1.25,0)
  51.     seat.Transparency = 0.1
  52.  
  53.     local seatbox = Instance.new("SelectionBox")
  54.     seatbox.Parent = seat
  55.     seatbox.Adornee = seat
  56.     seatbox.LineThickness = 0.05
  57.     seatbox.Color3 = Color3.fromRGB(255,255,255)
  58.  
  59.     local box = Instance.new("SelectionBox")
  60.     box.Parent = part
  61.     box.Adornee = part
  62.     box.LineThickness = 0.05
  63.     box.Color3 = Color3.fromRGB(255,255,255)
  64.  
  65.     local weld = Instance.new("Weld")
  66.     weld.Parent = part
  67.     weld.Name = "SeatWeld"
  68.     weld.Part0 = part
  69.     weld.Part1 = seat
  70.  
  71.     local seated = false
  72.  
  73.     seat.Touched:Connect(function(hit)
  74.         if seated == false then
  75.             if hit.Parent:FindFirstChild("Humanoid") then
  76.                 seated = true
  77.                 local playerWeld = Instance.new("WeldConstraint")
  78.                 playerWeld.Parent = seat
  79.                 playerWeld.Part0 = seat
  80.                 playerWeld.Part1 = game.Players.LocalPlayer.Character.HumanoidRootPart
  81.                 UIS.InputBegan:Connect(function(input)
  82.                     if input.KeyCode == Enum.KeyCode.Space then
  83.                         playerWeld:Destroy()
  84.                         seated = false
  85.                     end
  86.                 end)
  87.             end
  88.         end
  89.     end)
  90.  
  91.     UIS.InputBegan:Connect(function(input)
  92.         if seated == true then
  93.             if input.KeyCode == Enum.KeyCode.W then
  94.                 while UIS:IsKeyDown(Enum.KeyCode.W) do
  95.                     part.CFrame = part.CFrame + (part.CFrame.LookVector*0.7)
  96.                     task.wait()
  97.                 end
  98.             elseif input.KeyCode == Enum.KeyCode.A then
  99.                 while UIS:IsKeyDown(Enum.KeyCode.A) do
  100.                     part.Orientation = part.Orientation + Vector3.new(0,2,0)
  101.                     task.wait()
  102.                 end
  103.             elseif input.KeyCode == Enum.KeyCode.S then
  104.                 while UIS:IsKeyDown(Enum.KeyCode.S) do
  105.                     part.CFrame = part.CFrame - (part.CFrame.LookVector*0.7)
  106.                     task.wait()
  107.                 end
  108.             elseif input.KeyCode == Enum.KeyCode.D then
  109.                 while UIS:IsKeyDown(Enum.KeyCode.D) do
  110.                     part.Orientation = part.Orientation - Vector3.new(0,2,0)
  111.                     task.wait()
  112.                 end
  113.             elseif input.KeyCode == Enum.KeyCode.E then
  114.                 while UIS:IsKeyDown(Enum.KeyCode.E) do
  115.                     part.CFrame = part.CFrame + (part.CFrame.UpVector*0.4)
  116.                     task.wait()
  117.                 end
  118.             elseif input.KeyCode == Enum.KeyCode.Q then
  119.                 while UIS:IsKeyDown(Enum.KeyCode.Q) do
  120.                     part.CFrame = part.CFrame + (-part.CFrame.UpVector*0.4)
  121.                     task.wait()
  122.                 end
  123.             end
  124.         end
  125.     end)
  126. else
  127.     game.Players.LocalPlayer.CharacterAdded:Connect(function()
  128.         task.wait(3)
  129.         local UIS = game:GetService("UserInputService")
  130.         local part = Instance.new("Part")
  131.         part.Position = game.Players.LocalPlayer.Character.Head.Position - Vector3.new(0,3,0)
  132.         part.Anchored = true
  133.         part.Parent = workspace
  134.         part.Name = "FlyingPart"
  135.         part.Size = Vector3.new(10,1,10)
  136.         part.Material = Enum.Material.ForceField
  137.         part.FrontSurface = Enum.SurfaceType.Hinge
  138.        
  139.         local seat = Instance.new("Seat")
  140.         seat.Parent = part
  141.         seat.Size = Vector3.new(0.1,1.5,0.1)
  142.         seat.Position = part.Position + Vector3.new(0,1.25,0)
  143.         seat.Transparency = 0.1
  144.        
  145.         local seatbox = Instance.new("SelectionBox")
  146.         seatbox.Parent = seat
  147.         seatbox.Adornee = seat
  148.         seatbox.LineThickness = 0.05
  149.         seatbox.Color3 = Color3.fromRGB(255,255,255)
  150.        
  151.         local box = Instance.new("SelectionBox")
  152.         box.Parent = part
  153.         box.Adornee = part
  154.         box.LineThickness = 0.05
  155.         box.Color3 = Color3.fromRGB(255,255,255)
  156.        
  157.         local weld = Instance.new("Weld")
  158.         weld.Parent = part
  159.         weld.Name = "SeatWeld"
  160.         weld.Part0 = part
  161.         weld.Part1 = seat
  162.        
  163.         local seated = false
  164.        
  165.         seat.Touched:Connect(function(hit)
  166.             if seated == false then
  167.                 if hit.Parent:FindFirstChild("Humanoid") then
  168.                     seated = true
  169.                     local playerWeld = Instance.new("WeldConstraint")
  170.                     playerWeld.Parent = seat
  171.                     playerWeld.Part0 = seat
  172.                     playerWeld.Part1 = game.Players.LocalPlayer.Character.HumanoidRootPart
  173.                     UIS.InputBegan:Connect(function(input)
  174.                         if input.KeyCode == Enum.KeyCode.Space then
  175.                             playerWeld:Destroy()
  176.                             seated = false
  177.                         end
  178.                     end)
  179.                 end
  180.             end
  181.         end)
  182.        
  183.         UIS.InputBegan:Connect(function(input)
  184.             if seated == true then
  185.                 if input.KeyCode == Enum.KeyCode.W then
  186.                     while UIS:IsKeyDown(Enum.KeyCode.W) do
  187.                         part.CFrame = part.CFrame + (part.CFrame.LookVector*0.7)
  188.                         task.wait()
  189.                     end
  190.                 elseif input.KeyCode == Enum.KeyCode.A then
  191.                     while UIS:IsKeyDown(Enum.KeyCode.A) do
  192.                         part.Orientation = part.Orientation + Vector3.new(0,2,0)
  193.                         task.wait()
  194.                     end
  195.                 elseif input.KeyCode == Enum.KeyCode.S then
  196.                     while UIS:IsKeyDown(Enum.KeyCode.S) do
  197.                         part.CFrame = part.CFrame - (part.CFrame.LookVector*0.7)
  198.                         task.wait()
  199.                     end
  200.                 elseif input.KeyCode == Enum.KeyCode.D then
  201.                     while UIS:IsKeyDown(Enum.KeyCode.D) do
  202.                         part.Orientation = part.Orientation - Vector3.new(0,2,0)
  203.                         task.wait()
  204.                     end
  205.                 elseif input.KeyCode == Enum.KeyCode.E then
  206.                     while UIS:IsKeyDown(Enum.KeyCode.E) do
  207.                         part.CFrame = part.CFrame + (part.CFrame.UpVector*0.4)
  208.                         task.wait()
  209.                     end
  210.                 elseif input.KeyCode == Enum.KeyCode.Q then
  211.                     while UIS:IsKeyDown(Enum.KeyCode.Q) do
  212.                         part.CFrame = part.CFrame + (-part.CFrame.UpVector*0.4)
  213.                         task.wait()
  214.                     end
  215.                 end
  216.             end
  217.         end)
  218.     end)
  219. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement