Issues with GetMarkerReachedSignal

Hello! I am trying to make a simple combat system where when a player presses f, an animation plays and when the punch makes contact, it deals damage. The issue I am having is that it is not processing when it has punched. I am attempting to acheive this by renaming one of the keyframes to “Hit” and using GetMarkerReachedSignal event.
image
And then just detecting when that keyframe is played. However it doesn’t seem to be reaching the keyframe for some reason.

Here is the script;

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animationsFolder = ReplicatedStorage:WaitForChild("Animations")
local punchAnimations = animationsFolder:GetChildren()
local damageRemote = ReplicatedStorage:WaitForChild("DamageRemote")

local function playRandomPunch()
	local randomAnimation = punchAnimations[math.random(1, #punchAnimations)]
	local animator = humanoid:FindFirstChildOfClass("Animator")
	if not animator then
		print("Animator not found")  
		return
	end

	local animationTrack = animator:LoadAnimation(randomAnimation)
	if not animationTrack then
		print("Failed to load animation: " .. randomAnimation.Name)  
		return
	end

	animationTrack:GetMarkerReachedSignal("Hit"):Connect(function()
		print("Hit marker reached")  -- DOESN'T PRINT

		damageRemote:FireServer()
		print("Fired damage remote")  
	end)

	animationTrack:Play()
	print("Playing animation: " .. randomAnimation.Name)  
end

UserInputService.InputBegan:Connect(function(input, isProcessed)
	if isProcessed then return end
	if input.KeyCode == Enum.KeyCode.F then
		print("F key pressed")  
		playRandomPunch()
	end
end)

As you can see, it’s not printed in the output. I’m not to familliar with how animations work but my only idea is to why it doesn’t work is that I have exported it from moon animator and so it can’t detect the keyframe?

Any help is apreiciated!

2 Likes

Did you make sure to re-publish the animation with the renamed Keyframe?

1 Like

I don’t see why I would have to publish it again, when I first published it, It already included the renamed keyframe.

1 Like

Sorry, I meant that I was wondering if you just simply forgot to upload the animation with the updates name


Basically, :GetMarkerReachedSignal is used to detect specific event markers (called Animation Events) that you have to place in your Rig manually when you’re editing your animation. Keyframes are not equal to animation events.

If you’re using the default Roblox animation editor, instructions on how to add Animation Events are included in the Doc above.

If you are using Moon Animator, you will have to:

  • Search for an object called Events that should be under your rig’s name when you edit your animation. If you don’t see it, click on the 3 dots next to your rig’s name and click “Animation Events”
  • Go to the mark in your animation where you want to add the animation marker, make sure you have Events selected, and simply press enter on your keyboard to add the animation event.
  • Double click the added marker to configure the added animation event.

From there, simply change the string you’re trying to find in :GetMarkerReachedSignal to the name of the Animation Event you’ve placed.

2 Likes

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