I have a gun shooting animations right here, and a Keyframe named “Pump” to play a sound when it’s reached, however, it keeps stacking:
https://gyazo.com/dd71ad051723a037a8b37376eacc5672
animations
is a table, shootWithPump
is a humanoid:LoadAnimation(animation).
animations.shootWithPump.KeyframeReached:Connect(function(name)
print(name)
if name == "Pump" then
PlayGunSound(TempTool.Sounds.Pump, TempTool.BodyAttach)
end
end)
This is the Keyframe named “Pump”
Why does this happen?
3 Likes
How do I only rename that specific Keyframe? Whenever I select the keyframe dot and click rename, it renames all keyframe in the same time stance.
1 Like
You should not be using the KeyframeReached event since it’s deprecated, use the :GetMarkerReachedSignal()
function instead. This function will return a RBXScriptSignal that will fire when the KeyframeMarker with the given name on it’s parameter is reached on the animation.
You can create a KeyframeMarker, AKA: Animation Event, by clicking on this button at the almost top-left of the Animation Editor window.
This
DevHub Article may be helpful.
4 Likes
Thanks for suggesting GerMarkerReachedSignal, however it still stack firing.
animations.shootWithPump:GetMarkerReachedSignal("Pump"):Connect(function()
PlayGunSound(TempTool.Sounds.Pump, TempToolBodyAttach, 20)
flingshell(TempTool)
end)
animations
is a table with humanoid:LoadAnimation, and this GetMarkerReachedSignal is inside a function, which is called when player inputs.
DarthFS
(DarthFS)
October 17, 2020, 3:17am
#6
Sorry for the late response, but since you are creating a connection you have to disconnect it so it does not stack.
local connection
connection = animations.shootWithPump:GetMarkerReachedSignal("Pump"):Connect(function()
connection:Disconnect()
PlayGunSound(TempTool.Sounds.Pump, TempToolBodyAttach, 20)
flingshell(TempTool)
end)
8 Likes
Thanks for the response despite that I have already move into a newer animation sound playing framework.
And damn how come I don’t know about connections back in the beginning of this year?
2 Likes