Right so it plays inside of my flying function.
I don’t want to post the entire function because it is very long with many checks that set flying = false.
However, here is the part where I use latch()
Summary
local Connection
Connection = game:GetService('RunService').Heartbeat:Connect(function()
local Suc, Err = pcall(function()
if Flying == true then
BV.Velocity = Vector3.new(0,0,0)
BV.Velocity = Cam.CFrame.LookVector * 50
wait(.5)
flylatch()
local Gravity = Controller.GravityUp
if (Gravity-Vector3.new(0, 1, 0)).Magnitude > .1 then
Flying = false
print("flying false do to gravity")
end
else
Connection:Disconnect()
BV:Destroy()
character.Animate.Disabled = false
humanoid.JumpPower = 0
end
end)
if not Suc and Err then
print(Err)
Connection:Disconnect()
BV:Destroy()
character.Animate.Disabled = false
humanoid.JumpPower = 0
end
end)
I have it inside of a RunService.Heartbeat
so that it will continuing firing, on top of that it only fires when Flying == True
.
Like I said I use other functions that set Flying = false
such as if the player jumps, .Touched, Gravity Changed.
So my first thought was that latch()
should not be playing after Flying == false
. But you can see in the GIF, even after the player has landed (.Touched and Gravity Changed btw), the function still fires for a second or so after:
https://gyazo.com/2887ad44d4308aa4b20c88ee79fa52f1
An even better example can be seen when the player latches to the something flat instead:
https://gyazo.com/c51b5a369d15a858ee05ccd6c10723df
You can see that the player cannot walk immediately because of this, which is bad because my game relies on fast movement and reaction.
EDIT:
I figured I better just include the entire code incase the error may be with how it is structured:
Summary
local Flying = false -- the functions that set flying = false still run after
humanoid:GetPropertyChangedSignal("JumpPower"):Connect(function(key)
if humanoid.JumpPower == 100 then
delay(5, function()
Flying = false
end)
Flying = true
print("Power Change Acknowledged")
wait(.5)
print("Flying State Began")
Flying = true
character.Animate.Disabled = true
-- ADD FLYING ANIMATION HERE
local BV = Instance.new("BodyVelocity", character.PrimaryPart)
BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
BV.Velocity = Vector3.new(0,0,0)
BV.Name = "FlightForce"
if StateTracker.State ~= "onRunning" and Flying == true then
print("State good")
local jumpcon
local touchcon
jumpcon = UIS.InputBegan:Connect(function(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.Space then
Flying = false
print("flying false do to jump")
jumpcon:Disconnect()
end
end)
for i, v in pairs(character:GetChildren()) do
if v:IsA("BasePart") then
touchcon = v.Touched:Connect(function(touch)
if not character:FindFirstChild(touch.Name) then
Flying = false
print("flying false do to touch")
touchcon:Disconnect()
end
end)
end
end
local Connection
Connection = game:GetService('RunService').Heartbeat:Connect(function()
local Suc, Err = pcall(function()
if Flying == true then
BV.Velocity = Vector3.new(0,0,0)
BV.Velocity = Cam.CFrame.LookVector * 50
wait(.5)
flylatch()
local Gravity = Controller.GravityUp
if (Gravity-Vector3.new(0, 1, 0)).Magnitude > .1 then
Flying = false
print("flying false do to gravity")
end
else
Connection:Disconnect()
BV:Destroy()
character.Animate.Disabled = false
humanoid.JumpPower = 0
end
end)
if not Suc and Err then
print(Err)
Connection:Disconnect()
BV:Destroy()
character.Animate.Disabled = false
humanoid.JumpPower = 0
end
end)
end
end
end)