Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is this animation track still able to be spammed?

Asked by
Azuc 112
5 years ago
Edited 5 years ago

I want them to have to wait for the animation to end before being able to repeat it, I don't want to use a wait statement as players can change which animation/emote they are doing and they have different lengths.

local function onDabUp(player)
    local Character = player.Character
    local Humanoid = Character:WaitForChild("Humanoid")
    local Animation = Character.Animation
    local Track = Humanoid:LoadAnimation(Animation)
        if not Track.IsPlaying then
        Track:Play()    
        else
    end
end

1 answer

Log in to vote
1
Answered by
LeadRDRK 437 Moderation Voter
5 years ago

In this function, you loaded the animation everytime it was executed. That means, everytime you execute the function, a new AnimationTrack would be created and it will be like another animation on its own, so even if you checked if it’s playing or not, it will always be false since it have no relation with the AnimationTrack that was created before which is probably playing. What you want to do here is to load the animation once, by moving the line that you defined the AnimationTrack (local Track ...) outside of the function. Also remember to use different variable names if you have multiple animations in one script.

Hope this helps.

Ad

Answer this question