How do you give a player the ability to fly?


Achieve

I want to make my own flying system, such as the Adonis flying command; so I may manipulate it and change it as I see fit. Plus, being able to fly would probably come in handy down the road. This would be triggered by hitting a GUI Button or hitting the E Key Button.

What I understand

  1. I know how to listen for the key to be pressed, I know how to go off a Text Button
  2. I know how to trigger things through a button press, whether key or text.

What I don’t understand

  1. I do not know how to make a player fly.
  2. I do not know how to make a player stop flying.
  3. I have no idea where to start when it comes to getting a player to fly.

Script

This is what I got but it’s mainly based off adonis and I’m not sure how I’d toggle this on and off.

CommandModule.Commands["Fly Command"].AllowedToFly[PlayerName] = {
					AllowedToFly = false,
					Fly = false,
					Noclip = false,
					Speed = 2,
					Function = function(plr,noclip,speed)
						if game.Players:FindFirstChild(PlayerName) and game.Players[PlayerName].Character and game.Players[PlayerName].Character:FindFirstChild("HumanoidRootPart") then
							local part = game.Players[PlayerName].Character:FindFirstChild("HumanoidRootPart")
							if part then
								local oldp = part:FindFirstChild("Fly_Position")
								local oldg = part:FindFirstChild("Fly_Gyro")
								local olds = part:FindFirstChild("Fly_Flight")
								if oldp then oldp:Destroy() end
								if oldg then oldg:Destroy() end
								if olds then olds:Destroy() end

								local flightPosition = Instance.new("BodyPosition")
								local flightGyro = Instance.new("BodyGyro")

								flightPosition.Name = "Flight_Position"
								flightPosition.MaxForce = Vector3.new(0, 0, 0)
								flightPosition.Position = part.Position
								flightPosition.Parent = part

								flightGyro.Name = "Flight_Gyro"
								flightGyro.MaxTorque = Vector3.new(0, 0, 0)
								flightGyro.CFrame = part.CFrame
								flightGyro.Parent = part
							end
						end
					end,
				}

Any assistance is appreciated.

2 Likes

Are you asking how to listen for the “E” input on a user’s keyboard? If so, please consider ContextActionService to bind functions to certain “keybinds” or other input methods.

1 Like

I probably should of clarified what I do understand and what I don’t. I’ve updated my post to reflect that, here’s what I do understand & what I don’t understand.

here is a video I made that will show you how to make a player character fly

2 Likes

Thank you very much for the video, very informative. I would like to recommend you add on a video where you teach people how to make a player fly while having it move in the direction of the camera. The best example would be the Adonis Flight Command.