So i am currently working on a fighting game which used KeyFrameReached to find a certain keyframe in my animations to activate a function that would make a hitbox that would make damage and continue with the combo but i cant get it to work without that part of the script i have tried using GetMarkerReachedSignal but i cant get it to work so i ask for help here. The issue i am having is at line 77 or…
punchTrack.KeyFrameReached:Connect(function(frame)
if frame == "Damage" then
hitTarget = createHitbox(Vector3.new(3, 3, 3), character.PrimaryPart.CFrame * CFrame.new(0, 0, -3), { character })
punchRe:FireServer(hitTarget, character, hitNum)
if hitNum == #punchAnims then
hitNum = 1
else
hitNum *= 1
end
The other part of the script it self (not the full script tho).
local function createHitbox(size, offset, ignore)
local hitbox = Instance.new("Part", character)
hitbox.Size = size
hitbox.CFrame = offset
hitbox.CanCollide = false
hitbox.CanQuery = false
hitbox.Transparency = 0
hitbox.Anchored = true
local hitConn
hitConn = hitbox.Touched:Connect(function()
hitConn:Disconnect()
end)
local target = nil
for i, v in pairs(hitbox:GetTouchingParts()) do
if v.Parent:FindFirstChild("Humanoid") and table.find(ignore, v.Parent) == nil then
if (target.PrimaryPart.Position - character.PrimaryPart.Position).Magnitude > (v.Parent.PrimaryPart.Position - character.PrimaryPart.Position).Magnitude then
target = v.Parent
end
else
target = v.Parent
end
end
game.Debris:AddItem(hitbox, 0.1)
if target then
return target
else
return nil
end
end
local function punch(actionName, inputState, inputType)
if inputState == Enum.UserInputState.Begin and canPunch then
canPunch = false
if tick() - lastPunch > 1 then
combo = 1
hitNum = 1
end
lastPunch = tick()
local animation = Instance.new("Animation", character)
animation.AnimationId = punchAnims[combo]
animation:Destroy()
local punchTrack = humanoid.Animator:LoadAnimation(animation)
punchTrack:Play()
local hitTarget = nil
punchTrack.KeyFrameReached:Connect(function(frame)
if frame == "Damage" then
hitTarget = createHitbox(Vector3.new(3, 3, 3), character.PrimaryPart.CFrame * CFrame.new(0, 0, -3), { character })
punchRe:FireServer(hitTarget, character, hitNum)
if hitNum == #punchAnims then
hitNum = 1
else
hitNum *= 1
end
end
end)
if combo == #punchAnims then
combo = 1
wait(1)
canPunch = true
else
combo *= 1
wait(.25)
canPunch = true
end
end
end