So I'm currently trying to make a fly script, whenever someone presses a letter they will (automatically) go up, instead of a slow levitation. But I want to know how can I stop BodyVelocity from floating me up? Is there a way that I can make it where my character just goes up in the air, doesn't move. Whenever a key is pressed W A S D Space and CTRL they will change positions and go up and down? I'm not sure if using BodyVelocity is the right way to make a fly but how do I stop the levitation? My code is
game:GetService("UserInputService").InputBegan:Connect(function(KeyDown, gameProcessed) if not gameProcessed then if KeyDown.KeyCode == Enum.KeyCode.E then local bv = Instance.new("BodyVelocity", game.Players.LocalPlayer.Character.HumanoidRootPart) bv.Velocity = Vector3.new(0, 5, 0) bv.Velocity = Vector3.new(4000, 4000, 4000) end end end)
If you're just trying to make the player float when he presses a button then I suppose this could help: https://scriptinghelpers.org/questions/19753/how-do-i-make-my-character-float
Also if you want to stop the force you can do it by either two ways, deleting the bodyforce that's countering gravity, or anchoring the player's Head, then making the force go in reverse. This code makes it where when the player jumps, it's creates a force of 196.2 * the mass of all of it's parts which counteracts roblox's gravity and causes the player to float:
local players = game:GetService("Players") local player = players.LocalPlayer local character = player.Character for _, v in pairs(character:GetChildren()) do if v:IsA("BasePart") then local mass = v:GetMass() local force = Instance.new("BodyForce") force.Name = 'float'; force.force = mass * Vector3.new(0, 196.2, 0) force.Parent = v end end