I am trying to create an animation that plays when you press a key, pauses once it reaches a marker, and unpauses once you let go of the key being held down. It currently pauses, but only unpauses if the key is let go before the animation reaches the stopping point. I have prints everywhere, and the marker event that is fired by ‘Release’ isn’t firing. I can’t seem to find a reason for it to not work, since the other event gets disconnected.
local module = {}
local pressOrRelease = 1
local function resetSpeed(animation)
while pressOrRelease == 1 do
wait()
end
animation:AdjustSpeed(1)
end
function module.F(player, inputType)
--Animation
local animation = Instance.new('Animation')
animation.AnimationId = 'rbxassetid://14140855498'
animation = player.Character.Humanoid:LoadAnimation(animation)
animation.Priority = Enum.AnimationPriority.Action4
local animEvent
local pos
if inputType == 'Pressed' then
animation:Play()
end
--Check event type
if inputType == 'Pressed' then
--Do move
--print('client F pressed')
pressOrRelease = 1
animation:Play()
animEvent = animation:GetMarkerReachedSignal('Hold'):Connect(function()
print('speed stopped')
animation:AdjustSpeed(0)
resetSpeed(animation)
animEvent:Disconnect()
end)
elseif inputType == 'Released' then
--Do move
--print('client F released')
print('2')
pressOrRelease = 2
animEvent = animation:GetMarkerReachedSignal('Release'):Connect(function()
print('animation stopped')
animation:Stop()
--Disconnect event
animEvent:Disconnect()
end)
end
end
ty for the help