I would like some feedback for this fly script that i made, and what could i improve in it

-- Simple Fly Script :)
local TweenService = game:GetService("TweenService")
local Player = game.Players.LocalPlayer
local Char = Player.Character
local PlayerModule = Player.PlayerScripts.PlayerModule
local FlyVelocity = Instance.new("LinearVelocity")
FlyVelocity.Attachment0 = Char:WaitForChild("HumanoidRootPart").RootAttachment
FlyVelocity.RelativeTo = Enum.ActuatorRelativeTo.World
FlyVelocity.MaxForce = math.huge
FlyVelocity.Parent = script
local AlignCharLook = Instance.new("AlignOrientation")
AlignCharLook.Attachment0 = Char:WaitForChild("HumanoidRootPart").RootAttachment
AlignCharLook.Mode = Enum.OrientationAlignmentMode.OneAttachment
AlignCharLook.MaxTorque = math.huge
AlignCharLook.Responsiveness = 50
AlignCharLook.Parent = script
local Camera = game.Workspace.CurrentCamera
local Direction = Vector3.new(0,0,0)
while task.wait() do
	Direction = require(PlayerModule.ControlModule):GetMoveVector()
	TweenService:Create(FlyVelocity,TweenInfo.new(0.3),{VectorVelocity = (Camera.CFrame.LookVector*-Direction.Z*script.Force.Value)+(Camera.CFrame.RightVector*Direction.X*script.Force.Value)}):Play()
	AlignCharLook.CFrame = Camera.CFrame.Rotation
end

image

Firtst thing you could improve on is the code’s readability

then we got things as game.Workspace (which you should just write “workspace”)
And possibly using a Heartbeat/RenderStepped connection instead of a while loop

other than that its a pretty good and smooth fly script

1 Like

Cool, needs some work but it is a great start. You did the hardest part 1st, alignment.
Got one a bit like this where a pose puts them in a flying position.

1 Like
-- // Services //
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")

-- // Player //
local Player = game.Players.LocalPlayer
local Char = Player.Character
local PlayerModule = Player.PlayerScripts.PlayerModule
local Camera = workspace.CurrentCamera
local Direction = Vector3.new(0,0,0)

-- // Fly Move //
local FlyVelocity = Instance.new("LinearVelocity")
FlyVelocity.Attachment0 = Char:WaitForChild("HumanoidRootPart").RootAttachment
FlyVelocity.RelativeTo = Enum.ActuatorRelativeTo.World
FlyVelocity.MaxForce = math.huge
FlyVelocity.Parent = script

-- // Align To Camera //
local AlignCharLook = Instance.new("AlignOrientation")
AlignCharLook.Attachment0 = Char:WaitForChild("HumanoidRootPart").RootAttachment
AlignCharLook.Mode = Enum.OrientationAlignmentMode.OneAttachment
AlignCharLook.MaxTorque = math.huge
AlignCharLook.Responsiveness = 50
AlignCharLook.Parent = script
local Camera = workspace.CurrentCamera

-- // Update //
RunService.Heartbeat:Connect(function(dt)
	Direction = require(PlayerModule.ControlModule):GetMoveVector()
	TweenService:Create(FlyVelocity,TweenInfo.new(0.3),{VectorVelocity = (Camera.CFrame.LookVector*-Direction.Z*script.Force.Value)+(Camera.CFrame.RightVector*Direction.X*script.Force.Value)+DirectionUpNDown}):Play()
	AlignCharLook.CFrame = Camera.CFrame.Rotation
end)

Fixed the hearthbeat and the workspace thing and im going to add some notes to the code for readability

1 Like

comments dont exactly add onto readablity
but you did improve it by adding new lines

1 Like

Actually don’t like rems like that. Always found them a waste of time.
The code was very readable, every single line is describing itself.

1 Like

Idk, both of them for me are readable, but some times when it’s too big i get lost, it wasnt that big thats why i didnt put anything

1 Like