How to detect animation events in Roblox default animator script?

  1. What do you want to achieve? Keep it simple and clear!
    I want to add events to roblox’s default animator script,

  2. What is the issue? Include screenshots / videos if possible!
    Don’t know how to do that.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I tried editing the “playAnimation” function, or trying to reach the marker in another script with the same animation ID, but none of them happened to work.

-- This is the function I edited from the default animator script
function playAnimation(animName, transitionTime, humanoid) 	
	local idx = rollAnimation(animName)
	local anim = animTable[animName][idx].anim
	
	anim:GetMarkerReachedSignal("Sparkle"):Connect(function()
		print("WORKS")
	end)

	switchToAnim(anim, animName, transitionTime, humanoid)
	currentlyPlayingEmote = false
end

-- this is the script that I used in another local script, neither worked

local animationId = "rbxassetid://17769800973" 

local function onMarkerReached(markerName)
	if markerName == "Sparkle" then
		print("WORKS")
		local vfx = game.ReplicatedStorage.Part.AttachmentA:Clone()
		vfx.Parent = game.Players.Localplayer.RightHand
		for _,v in pairs (vfx:GetChildren()) do
			if v:IsA("ParticleEmitter") then
				v:Emit(2)
			end
		end
	end
end

local humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
local animation = Instance.new("Animation")
animation.AnimationId = animationId
local loadedAnimation = humanoid:LoadAnimation(animation)

loadedAnimation:GetMarkerReachedSignal():Connect(onMarkerReached)
loadedAnimation:Play()

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.