Need help with Zairky's flight script, animations break when landing

  1. 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.

  2. 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:

  1. 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!

1 Like

Hello,

Since it’s a bit too complicated to read the entire thing through, I’d advise you to detect when the player stops walking and stop the walk animation with animation:Stop();.

You can find a fly script here.

Hi! That’s the script I was working off of. It’s okay if you don’t have time to read, but I mentioned in the post that the issue is with the animation playing after I land. So stopping it during flight is taken care of. I’ll try to implement that, though.

Hi! I’m glad to see the post I wrote was useful for you. I think you might be having trouble with this particular property:

AnimationTrack | Documentation - Roblox Creator Hub

Whichever animation is supposed to run whilst flying should have its animation priority set to Action (if you don’t want anything to override it) and also should be set to looped. Additionally, make sure this animation controls every part in the rig. If you have uncontrolled parts, lower priority animations will play over them.

Back when I was responsible for animations in my games, these properties had to be set in studio’s animation editor. I’m not sure if they can now be manually overridden in scripts, but if not, open up the animation in studio and set them.

If this doesn’t work, just let me know ^^

1 Like

OHHHH that makes so much more sense than disabling the script! Thank you so much for the script and the help! It works now <:]

1 Like