I’ve got an animation with different AnimationEvents indicating points at which the track should stop to wait for player input. The animation plays perfectly the first time, stopping at the right keyframe to wait for the player to release their right mouse button. But when using the skill again it doesn’t seem to stop or play at the right time. I do not know where the delay in the animation is coming from.
Video of the issue
The video should show how the “Pulling the arm back” part of the animation gets delayed after each use.
AnimationEvents in the animation:
My (local)script:
local character = script.Parent
local hrp = character:FindFirstChild("HumanoidRootPart") or character:WaitForChild("HumanoidRootPart")
local humanoid = character:FindFirstChild("Humanoid") or character:WaitForChild("Humanoid")
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
mouse.TargetFilter = character
local grappleAcc = character:FindFirstChild("GrappleBand") or character:WaitForChild("GrappleBand")
local grappleCore = grappleAcc.Handle
local baseAtt = grappleAcc.GrapplePoint:FindFirstChild("baseAtt")
local projAtt = grappleAcc.GrapplePoint:FindFirstChild("projAtt")
local projAttPos = projAtt.Position
local lineBeam = grappleAcc.GrapplePoint:FindFirstChild("line")
local TweenServ = game:GetService("TweenService")
local grappleAnim = script.rnsGrapplePull
local grappleAnimTrack = humanoid.Animator:LoadAnimation(grappleAnim)
local UIServ = game:GetService("UserInputService")
local debounce = false
local pressed = false
local function onInputBegan(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.MouseButton2 and not debounce then
debounce = true
pressed = true
grappleAnimTrack:Play(0)
grappleAnimTrack:GetMarkerReachedSignal("grappleAiming"):Connect(function()
grappleAnimTrack:AdjustSpeed(0)
humanoid.WalkSpeed = 0
end)
end
end
end
local function onInputEnded(input,gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.MouseButton2 and pressed then
pressed = false
local hitPart
if mouse.Target then
hitPart = mouse.Target
else
grappleAnimTrack:Stop()
humanoid.WalkSpeed = 16
wait(1)
debounce = false
end
local origin = baseAtt.Position
local direction = (mouse.Hit.Position - origin).Unit * 100
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {character}
local rayResult = workspace:Raycast(origin,direction,params)
if rayResult then
print("found point")
lineBeam.Enabled = true
local tweenInfoAtt = TweenInfo.new(0.7,Enum.EasingStyle.Circular,Enum.EasingDirection.InOut)
local goalAtt = {}
goalAtt.WorldPosition = rayResult.Position
local tweenAtt = TweenServ:Create(projAtt,tweenInfoAtt,goalAtt)
tweenAtt:Play()
tweenAtt.Completed:Wait()
projAtt.Parent = rayResult.Instance
projAtt.WorldPosition = rayResult.Position
local tweenInfoBeam = TweenInfo.new(0.25,Enum.EasingStyle.Linear)
local goalBeam = {}
goalBeam.CurveSize0 = 0
goalBeam.CurveSize1 = 0
local tweenBeam = TweenServ:Create(lineBeam,tweenInfoBeam,goalBeam)
tweenBeam:Play()
tweenBeam.Completed:Wait()
grappleAnimTrack:AdjustSpeed(1)
grappleAnimTrack:GetMarkerReachedSignal("grappleMoving"):Connect(function()
grappleAnimTrack:AdjustSpeed(0)
end)
local alignPos = Instance.new("AlignPosition")
alignPos.Position = rayResult.Position
alignPos.Attachment0 = baseAtt
alignPos.Attachment1 = projAtt
alignPos.ApplyAtCenterOfMass = true
alignPos.RigidityEnabled = true
alignPos.ReactionForceEnabled = false
alignPos.Parent = hrp
repeat
wait()
until (alignPos.Position - alignPos.Attachment0.WorldPosition).Magnitude < 5
print("reached")
lineBeam.Enabled = false
lineBeam.CurveSize0 = 5
lineBeam.CurveSize1 = 5
projAtt.Parent = grappleAcc.GrapplePoint
projAtt.Position = projAttPos
grappleAnimTrack:Stop()
humanoid.WalkSpeed = 16
wait(1)
debounce = false
else
grappleAnimTrack:Stop()
humanoid.WalkSpeed = 16
wait(1)
debounce = false
end
end
end
end
UIServ.InputBegan:Connect(onInputBegan)
UIServ.InputEnded:Connect(onInputEnded)
I tried to search for other posts about this but I didn’t find anything specific to this problem. I might’ve misunderstood something about how animations/animation events work in general.