Need help making a flight script

Hello there, I am a beginner scripter, and are currently making a game.

Basically, my issue is, I want to make a flight script (Not a :fly command script).

I have absolutely no idea what I’m doing for this, so if anyone could help me with it, that would be great!
I’m looking to have it be sort of like an elytra from Minecraft if you understand, but I want it so you can propel off the ground and fly up instantly.

I’m not asking for anyone to make a script, as that is asking for a lot in my opinion, I’m asking if anyone could give me some tips, or strings of code that can help with making it.

All help is appreciated, little, or lots, thanks in advance for anyone helping out!

PS: I’m not advanced at scripting, so if it’s not a hassle, please explain some of your code, that would be greatly appreciated, thanks!

Edit: reformatted, added info.

4 Likes

I suggest using BodyVelocity although it wont exactly be like the minecraft elytra but it still flies :slight_smile:
Lets say we place it in a local script

LOCAL SCRIPT

local speed = 30 --The Speed of the flight
local player = game.Players.LocalPlayer --Refer the player
local mouse = player:GetMouse() --Lets get the players mouse so we can get the flying direction 
local character = ple.Character or plr.CharacterAdded:Wait() --Lets wait for the character to be added
local BV = Instance.new("BodyVelocity",character:WaitForChild("HumanoidRootPart") --Lets create our BodyVelocity and parent it to the HumanoidRootPart of our player
BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge) --We set it to infinite so our player wont fall.

mouse.Move:Connect(function() --Detect when the mouse moves
  BV.Velocity = CFrame.new(character.HumanoidRootPart.Position,mouse.Hit.Position).LookVector * SPEED --Set Velocity to the mouse position everytime the mouse moves
end)

As I said this is just a simple fly script, even when you fly the player would look like its falling(Just add animations) and the player wont face its direction(use simple CFrame)

5 Likes

So how would I set a bind to being that action? (I want to use F)

Edit: I was just using the Minecraft Elytra as an example, I don’t want it to be exactly like it.

Simply use UserInputService or ContextActionService
(We will use UIS)

local Bind = false
local UIS = game:GetService("UserInputService")
BV.MaxForce Vector3.new(0,0,0)
UIS.InputBegan:Connect(function(input)
   if input.KeyCode == Enum.KeyCode.F and not Bind then
     Bind = true
   elseif input.KeyCode == Enum.KeyCode.F and Bind then
      Bind = false
    end
end)
mouse.Move:Connect(function() --Detect when the mouse moves 
if Bind then
BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
BV.Velocity = CFrame.new(character.HumanoidRootPart.Position,mouse.Hit.Position).LookVector * SPEED --Set Velocity to the mouse position everytime the mouse moves 
end
2 Likes

Okay, thanks a lot. Like I said, I’m very new to scripting, only started a month ago, so I haven’t really done much with it, and am still trying to learn more about events, userinputservices, and more.

1 Like

I’m getting Error:(6,1) Expected ‘)’ (to close ‘(’ at line 5), got ‘BV’

Replace

BV.MaxForce Vector3.new(0,0,0)

With this

BV.MaxForce = Vector3.new(0,0,0)
1 Like

Even after doing what you told me to do, I have 5 warnings
(3,19) Unknown global ‘ple’
(3,36) Unknown global ‘plr’
(5,1) Assigning 2 values to 1 variable leaves some values unused
(9,97) Unknown global ‘SPEED’
(25,97) Unknown global ‘SPEED’

Mind, this is when putting the first script posted in, then the seconds script posted in, then doing what you told me to do, I copy pasted the script, I didn’t rewrite it. I also fixed an error at (6,1) where there was a missing bracket.

Edit: I think this is just bad coding tbh, I feel like it was writen, but not tested, that’s why I think I’m getting errors, plus the fact that there was a missing bracket, and speed is caps fsr.

Please send your full code, is it even a local script

1 Like
local player = game.Players.LocalPlayer --Refer the player
local mouse = player:GetMouse() --Lets get the players mouse so we can get the flying direction
local character = ple.Character or plr.CharacterAdded:Wait() --Lets wait for the character to be added
local BV = Instance.new("BodyVelocity",character:WaitForChild("HumanoidRootPart") --Lets create our BodyVelocity and parent it to the HumanoidRootPart of our player
BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge) --We set it to infinite so our player wont fall.
 
mouse.Move:Connect(function() --Detect when the mouse moves
  BV.Velocity = CFrame.new(character.HumanoidRootPart.Position,mouse.Hit.Position).LookVector * SPEED --Set Velocity to the mouse position everytime the mouse moves
end)
 
local Bind = false
local UIS = game:GetService("UserInputService")
BV.MaxForce Vector3.new(0,0,0)
UIS.InputBegan:Connect(function(input)
   if input.KeyCode == Enum.KeyCode.F and not Bind then
     Bind = true
   elseif input.KeyCode == Enum.KeyCode.F and Bind then
      Bind = false
    end
end)
mouse.Move:Connect(function() --Detect when the mouse moves
if Bind then
BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
BV.Velocity = CFrame.new(character.HumanoidRootPart.Position,mouse.Hit.Position).LookVector * SPEED --Set Velocity to the mouse position everytime the mouse moves
end

The problem is here

local player = game.Players.LocalPlayer --Refer the player
local mouse = player:GetMouse() --Lets get the players mouse so we can get the flying direction local 
character = player.Character or player.CharacterAdded:Wait() --Lets wait for the character to be added(You didnt change ple and plr to player as we defined :/
 local BV = Instance.new("BodyVelocity",character:WaitForChild("HumanoidRootPart")) --Lets create our BodyVelocity and parent it to the HumanoidRootPart of our player 
BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
1 Like

I don’t understand? Can you please elaborate?

You see a line that looks the same as the message I quoted right? If so then replace the look alike with the message that I quoted.

1 Like

Look, this is getting a lot more confusing than it needs to be, I fixed the code, and now I’m getting Error:(13,1) Incomplete statement: expected assignment for function call

Add in another end) at the bottom.

1 Like

Nothing that anyone suggests is working, I doubt the code was even tested, if it was tested, it would work.

Why are you so mad? We are here to support, and if it doesn’t work, it’s on you to figure out the root of the problem. Don’t blame us because we can’t help you, there are literally obvious errors in the code.

2 Likes

I’m not mad at all, I’m just saying that I feel the code wasn’t tested, as it never worked, no matter who tried to fix it, or who made it.

Edit: Not to mention, I said I am a new scripter, and I had no idea what to do for a fly script, that’s why I came to the devforums, I can’t fix these errors when I have no idea what to do.

local player = game.Players.LocalPlayer --Refer the player
local mouse = player:GetMouse() --Lets get the players mouse so we can get the flying direction
local character = player.Character or player.CharacterAdded:Wait() --Lets wait for the character to be added
local BV = Instance.new("BodyVelocity",character:WaitForChild("HumanoidRootPart")) --Lets create our BodyVelocity and parent it to the HumanoidRootPart of our player

local speed = 5
 
local Bind = false
local UIS = game:GetService("UserInputService")
BV.MaxForce = Vector3.new(0,0,0)
UIS.InputBegan:Connect(function(input)
   if input.KeyCode == Enum.KeyCode.F and not Bind then
     Bind = true
     BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
   elseif input.KeyCode == Enum.KeyCode.F and Bind then
      Bind = false
      BV.MaxForce = Vector3.new()
    end
end)
mouse.Move:Connect(function() --Detect when the mouse moves
BV.Velocity = CFrame.new(character.HumanoidRootPart.Position,mouse.Hit.Position).LookVector * speed--Set Velocity to the mouse position everytime the mouse moves
end)

I’ve fixed all the errors I could see. Hopefully that works for you.

5 Likes

The flight doesn’t activate when I hit F