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.
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!