Why is .KeyframeReached not working?

Hello, currently im try to create a knife to become visible when the event reaches yes its the right name Ive checked 20 times

its on a client inside a tool

heres a video

robloxapp-20250103-1925339.wmv (653.4 KB)

knife should spawn when pulled behind

thanks any help appreciated!

3 Likes

Try defining it before playing the animation. I always do this and it worked for me
And incase KeyframeReached yields the script without indication, wrap it inside a task.spawn()

local EquipTrack = animator:LoadAnimation(EquipAnimation)
currentAnim["Equip"] = EquipTrack

EquipTrack.KeyframeReached:Connect(function(event)
	print("Reached keyframe: " .. event)
	if event == "Equip" then
		print("Equip Keyframe Triggered")
		tool.Handle.Transparency = 0
	end
end)

EquipTrack:Play()
6 Likes

I tried it like this

	local EquipTrack = animator:LoadAnimation(EquipAnimation)
	currentAnim["Equip"] = EquipTrack
	
	task.spawn(function()
		EquipTrack.KeyframeReached:Connect(function(event)
			print("Reached keyframe: " .. event)
			if event == "Equip" then
				print("Equip Keyframe Triggered")
				tool.Handle.Transparency = 0
			end
		end)
	end)
	
	EquipTrack:Play()

but still it doesnt work even though the animation is playing.

3 Likes

does it have to do with it being inside another connect function?

tool.Equipped:Connect(function()
	local character = player.Character or player.CharacterAdded:Wait()
	local humanoid = character:WaitForChild("Humanoid")
	local animator = humanoid:FindFirstChildOfClass("Animator") -- Recommended for animations

	-- Play Equip Animation
	local EquipTrack = animator:LoadAnimation(EquipAnimation)
	currentAnim["Equip"] = EquipTrack
	
	task.spawn(function()
		EquipTrack.KeyframeReached:Connect(function(event)
			print("Reached keyframe: " .. event)
			if event == "Equip" then
				print("Equip Keyframe Triggered")
				tool.Handle.Transparency = 0
			end
		end)
	end)
	
	EquipTrack:Play()
2 Likes

Weird, maybe try this?

	local EquipTrack = animator:LoadAnimation(EquipAnimation)
	local KeyframeReached = nil
	currentAnim["Equip"] = EquipTrack
	
	task.spawn(function()
		KeyframeReached = EquipTrack.KeyframeReached:Connect(function(event)
			print("Reached keyframe: " .. event)
			if event == "Equip" then
				print("Equip Keyframe Triggered")
				tool.Handle.Transparency = 0
			end
		end)
	end)
	
	print(KeyframeReached) -- Ensure the connection is defined.
	EquipTrack:Play()
2 Likes

If the EquipAnim variable is defined inside the Equipped function, then the KeyframeReached should also.

2 Likes

yeah it shows the connection but the prints inside still dont print. Could this be an error inside of roblox?

2 Likes

maybe becuase it’s a tool it doesnt work

1 Like

Try using GetMarkerReachedSignal()

local EquipTrack = animator:LoadAnimation(EquipAnimation)
currentAnim["Equip"] = EquipTrack

EquipTrack:GetMarkerReachedSignal("Equip"):Connect(function()
	print("Reached keyframe: " .. event)
	print("Equip Keyframe Triggered")
	tool.Handle.Transparency = 0
end)

EquipTrack:Play()
2 Likes

OMG thank you I knew there was another way to do it but I forgot about it :sob:.Tysm is it becuase .keyframereached is deprecated?

1 Like

KeyframeReached isn’t deprecated, you might’ve created a marker instead of renaming the frame of when the knife should appear

2 Likes

okay thanks for letting me know!

2 Likes

Screenshot 2025-01-03 194347
for future reference this is what .KeyframeReached is for (you rename the actual frame inside the KeyframeSequence before you publish the animation)

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.