Hello! i have a flying script, that works pretty well and for the most part its exactly how i want it, the problem however, is that when i activate the flying while pressing W, the walking animation continues to play when i land, even if i am not moving.
i am using a custom model with custom animations too, so that could also be a problem possibly?
It doesnt happen if i start flying when im not moving however, does anyone know how to fix this?
here is the flying script i am using:
local KeyCode = Enum.KeyCode.F
local HoverAnimID = "rbxassetid://17402721184"
local FlyAnimID = "rbxassetid://17402055688"
local FlylAnimID = "rbxassetid://17402082521"
local FlyrAnimID = "rbxassetid://17402066227"
local BodyVelocity = script:WaitForChild("BodyVelocity"):Clone()
local v3 = script.BodyGyro:Clone()
local Player = game.Players.LocalPlayer
local Character = script.Parent
local Humanoid = Character:FindFirstChild("Humanoid") or Character:WaitForChild("Humanoid")
BodyVelocity.Parent = Character
v3.Parent = Character
local Hover = Instance.new("Animation")
Hover.AnimationId = HoverAnimID
local Fly = Instance.new("Animation")
Fly.AnimationId = FlyAnimID
local FlyR = Instance.new("Animation")
FlyR.AnimationId = FlyrAnimID
local FlyL = Instance.new("Animation")
FlyL.AnimationId = FlylAnimID
local canfly = Character:WaitForChild("Flight")
canfly.Value = true
local v10 = Humanoid.Animator:LoadAnimation(Hover)
local v11 = Humanoid.Animator:LoadAnimation(Fly)
local v12 = Humanoid.Animator:LoadAnimation(FlyL)
local v13 = Humanoid.Animator:LoadAnimation(FlyR)
local Camera = game.Workspace.Camera
local function u2()
if Humanoid.MoveDirection == Vector3.new(0, 0, 0) then
return Humanoid.MoveDirection
end
local v12 = (Camera.CFrame * CFrame.new((CFrame.new(Camera.CFrame.p, Camera.CFrame.p + Vector3.new(Camera.CFrame.lookVector.x, 0, Camera.CFrame.lookVector.z)):VectorToObjectSpace(Humanoid.MoveDirection)))).p - Camera.CFrame.p;
if v12 == Vector3.new() then
return v12
end
return v12.unit
end
local Flymoving = script.Flymoving
local TweenService = game:GetService("TweenService")
local UIS = game:GetService("UserInputService")
local Flying = false
game:GetService("RunService").RenderStepped:Connect(function()
if script.Parent == Character then
if canfly.Value == true then
if Flying == true then
Humanoid:ChangeState(6)
v3.CFrame = game.Workspace.Camera.CFrame
if u2() == Vector3.new(0, 0, 0) then
Flymoving.Value = false
else
Flymoving.Value = true
end
TweenService:Create(BodyVelocity, TweenInfo.new(0.3), {Velocity = u2() * 100}):Play()
end
elseif canfly == false then return end
end
end)
Flymoving.Changed:Connect(function(p1)
if p1 == true then
v10:Stop()
v11:Play()
return
end
if p1 == false then
v11:Stop()
v10:Play()
end
end)
local xractivated = false
UIS.InputBegan:Connect(function(key, gameProcessed)
if gameProcessed then return end
if key.KeyCode == KeyCode then
if canfly.Value == true then
if Flying == false then
Flying = true
if Character:FindFirstChild("HumanoidRootPart") then
Character.Animate.Disabled = true
Character.jump.Disabled = true
v10:Play(0.1, 1, 1)
Character.HumanoidRootPart.Running.Volume = 0
BodyVelocity.Parent = Character.HumanoidRootPart
v3.Parent = Character.HumanoidRootPart
end
else
Flying = false
Flymoving.Value = false
Character.Animate.Disabled = false
Character.jump.Disabled = false
Character.HumanoidRootPart.Running.Volume = 0.65
Humanoid:ChangeState(8)
BodyVelocity.Parent = Character
v3.Parent = Character
v12:Stop()
v13:Stop()
v10:Stop()
v11:Stop()
end
elseif canfly.Value == false then return end
end
end)
UIS.InputBegan:Connect(function(key, gameProcessed)
if gameProcessed then return end
if key.KeyCode == Enum.KeyCode.A then
if Flying == true then
v10:Stop()
v11:Stop()
v12:Play()
end
end
if key.KeyCode == Enum.KeyCode.D then
if Flying == true then
v10:Stop()
v11:Stop()
v13:Play()
end
end
end)
UIS.InputEnded:Connect(function(key, gameProcessed)
if gameProcessed then return end
if key.KeyCode == Enum.KeyCode.A then
if Flying == true then
v10:Stop()
v11:Play()
v12:Stop()
end
end
if key.KeyCode == Enum.KeyCode.D then
if Flying == true then
v10:Stop()
v11:Play()
v13:Stop()
end
end
end)
canfly:GetPropertyChangedSignal("Value"):Connect(function()
if canfly.Value == false then
Flying = false
Flymoving.Value = false
v12:Stop()
v13:Stop()
v10:Stop()
v11:Stop()
Character.Animate.Disabled = false
Character.jump.Disabled = false
Character.HumanoidRootPart.Running.Volume = 0.45
Humanoid:ChangeState(8)
BodyVelocity.Parent = Character
v3.Parent = Character
end
end)