This is a very overdone topic I am aware. But I’m just so frustrated I need personal help with this one.
I’m trying to make it so my npc only moves when it hops using animation events. Hypothetically my code should work, but it doesn’t. I have looked at similar forum posts and most of them reccomend either adding the animation events (i have). Here is my code:
local Animator = TeethModel.Humanoid.Animator
local WalkCycleAnim = TeethModel.WalkCycle
local loadedWalk: AnimationTrack = Animator:LoadAnimation(WalkCycleAnim)
loadedWalk:GetMarkerReachedSignal("Hop"):Connect(function(params)
print("Hop!")
if active and wayPoints[currentWaypointIndex] then
local rootPart = TeethModel.PrimaryPart
local targetPosition = wayPoints[currentWaypointIndex].Position
local direction = (targetPosition - rootPart.Position).Unit
rootPart.CFrame = rootPart.CFrame + direction * hopDistance
local distanceToWaypoint = (targetPosition - rootPart.Position).Magnitude
if distanceToWaypoint < hopDistance * 1.5 then
currentWaypointIndex = currentWaypointIndex + 1
end
end
end) -- Ignore how weird this code block looks it pasted weirdly (thanks new studio ui)
and then further down
if success and path.Status == Enum.PathStatus.Success and active then
if not loadedWalk.IsPlaying then
loadedWalk:Play()
end
Here is my animation:
There is no hidden space after the event name
