Hey, I’ve been working on some custom commands using cmdr recently, and I came up with an idea to create a command that would let admins fly. However, I’m completely lost when it comes to the logic behind implementing flight.
Step 1: Handle the command on the server
- Create a
LocalScript
and place it intoServerStorage
. Let’s call itFlyScript
. Disable it. - Command handler on the server (example as a module):
function commands.fly(player: Player)
local flyScript = game:GetService("ServerStorage").FlyScript:Clone()
flyScript.Parent = player.Character
flyScript.Enabled = true
end
Step 2: Structure for the fly script
- This structure is designed for PC
- This fly script is on the client because we need user input.
- You need to listen for when user input begins and when it ends.
- You need a main variable to control the velocity, and you will also need direction values for each key.
- When a key is pressed, add the directional value to the overall velocity. Assign this as the
AssemblyLinearVelocity
of theHumanoidRootPart
. - When a key goes up, remove this added directional velocity. Assign the new velocity as the
AssemblyLinearVelocity
of theHumanoidRootPart
. - Make sure the
HumanoidRootPart
is anchored.