-
What do you want to achieve?
Hi again! I’m really happy that this forum’s been super helpful and kind to me. I’m trying to make this flight script from Zairky (I won’t ping them since it’s an older post) work with my game. I’m VERY new to scripting, so there will def be issues with the script. -
What is the issue?
The only heavy issue with the script is that my animations break when I use the WASD or the spacebar while I press Q to land.
Yesterday, though, it was doing this thing where the running animations would play while the player took off from the ground and not from mid-air. I think disabling the emote scripts was what fixed that.
This is what I want:
This is what happens:
-
What solutions have you tried so far?
My models are custom, so not a lot of threads can find the answer for me. I’ll post my script.
wait()
local uis = game:GetService("UserInputService")
local rs = game:GetService("RunService")
local myPlayer = game.Players.LocalPlayer
local myChar = myPlayer.Character
local myHRP = myChar:WaitForChild("HumanoidRootPart")
local camera = game.Workspace.CurrentCamera
local hum = myChar.Humanoid
local FA = Instance.new("Animation")
FA.AnimationId = "rbxassetid://6489434672"
local FlyAnim = script.Parent.Humanoid:LoadAnimation(FA)
local flying = false
local speed = .5
local bp = Instance.new("BodyPosition", myHRP)
bp.MaxForce = Vector3.new()
bp.D = 10
bp.P = 10000
local bg = Instance.new("BodyGyro", myHRP)
bg.MaxTorque = Vector3.new()
bg.D = 10
function fly()
flying = true
bp.MaxForce = Vector3.new(400000,400000,400000)
bg.MaxTorque = Vector3.new(400000,400000,400000)
FlyAnim:play()
hum.WalkSpeed = 0
hum.JumpHeight = 0
script.Parent["Walk anim 2"].Disabled = true
script.Parent["Run anim"].Disabled = true
script.Parent["Double jump"].Disabled = true
script.Parent.Jump2.Disabled = true
script.Parent.Chairsit.Disabled = true
script.Parent.Floorsit.Disabled = true
script.Parent.Sleep.Disabled = true
script.Parent.Sprint.Disabled = true
while flying do
rs.RenderStepped:wait()
bp.Position = myHRP.Position +((myHRP.Position - camera.CFrame.p).unit * speed)
bg.CFrame = CFrame.new(camera.CFrame.p, myHRP.Position)
end
end
function endFlying()
FlyAnim:stop()
bp.MaxForce = Vector3.new()
bg.MaxTorque = Vector3.new()
flying = false
wait()
hum.WalkSpeed = 12
hum.JumpHeight = 100
script.Parent["Walk anim 2"].Disabled = false
script.Parent["Run anim"].Disabled = false
script.Parent["Double jump"].Disabled = false
script.Parent.Jump2.Disabled = false
script.Parent.Chairsit.Disabled = false
script.Parent.Floorsit.Disabled = false
script.Parent.Sleep.Disabled = false
script.Parent.Sprint.Disabled = false
end
function onKeyPress(actionName, userInputState, inputObject)
if userInputState == Enum.UserInputState.Begin then
if not flying then
fly()
else
endFlying()
end
end
end
game.ContextActionService:BindAction("Fly", onKeyPress, true, Enum.KeyCode.Q)
game.ContextActionService:SetPosition("Fly", UDim2.new(.5,0,-.125,0))
game.ContextActionService:SetImage("Fly", "rbxassetid://6264154092")
The reason I manually disable all other scripts is because I just… don’t know a better way yet. It’s probably going to cause some performance issues if I do it like that, but maybe soon I’ll learn a more efficient way of doing it. When they’re enabled, players can go into the sit or sleep animations mid-flight, the run and walk animations lets the character walk while flying, and the double jump script lets them play the jump animation. I don’t want any of this possible.
I also noticed RenderStepped is deprecated, but I couldn’t find an alternative that I understood. Doing Controls:Disable() breaks movement for the other playable characters.
Thanks in advance for any advice!