I am working on a battle royale game where players to be able to click to attack and click and hold to charge up attacks. I’m currently using a single animation for the normal and charged variants of the attack. I want the script to check when the player begins a click, play a certain percentage of an animation until they reach a keyframe marker (“SwingStart”) and then stop and wait for the player to release the click to continue the animation out.
The issue is that the code doesn’t recognize the SwingStart and SwingEnd functions. Output keeps on saying ‘Passed value is not a function’ referring to when I connect the events to their appropriate functions.
If anyone has an idea of how I can fix this or how I can find a better way to create a charging animation please lemme know.
local attack_anim_track = nil
local onSwingStart = nil
local onSwingEnd = nil
function SwingStart()
print("swing started")
attack_anim_stop_time = attack_anim_track.TimePosition
attack_anim_track:Stop()
end
function SwingEnd()
print("swing ended")
end
function anims:attack(humState,inputState)
if inputState == Enum.UserInputState.Begin then
attack_anim_track = hum:LoadAnimation(animations.attack["swing1"])
onSwingStart = attack_anim_track:GetMarkerReachedSignal("SwingStart")
onSwingEnd = attack_anim_track:GetMarkerReachedSignal("SwingEnd")
attack_anim_track:Play()
onSwingStart:Connect(SwingStart)
end
elseif inputState == Enum.UserInputState.End then
attack_anim_track:Play()
attack_anim_track.TimePosition = attack_anim_stop_time
-- fire 'attack_in' event
onSwingEnd:Connect(SwingEnd)
end
end