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

Why Isn't My Guarding Animation Not Stopping??

Asked by 4 years ago

I'm making a mini basketball game project and I want to add guarding so I made a script for the animation to play but why isn't it stopping?? Please help.

local plr = game.Players.LocalPlayer
local chr = plr.Character
local humanoid = chr.Humanoid
local uis = game:GetService("UserInputService")

local animid = 'rbxassetid://3312318024'
local db = true

uis.InputBegan:connect(function(input,gpe)
    if gpe then
        return
    end
    if input.KeyCode == Enum.KeyCode.G then
        local anim = Instance.new("Animation")
        anim.AnimationId = animid
        local LoadAnimation = humanoid:LoadAnimation(anim)
        LoadAnimation:Play()
    end
end)

uis.InputEnded:connect(function(input,gpe)
    if gpe then
        return
    end
    if input.KeyCode == Enum.KeyCode.G then
        db = false
        local anim = Instance.new("Animation")
        anim.AnimationId = animid
        local LoadAnimation = humanoid:LoadAnimation(anim)
        anim:Destroy()
        db = true
    end
end)
0
Best Game Ever! RobloxBuildingCareer 0 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Do not delete the animation, instead, use LoadAnimation:Stop This will halt the animation and then you can play it whenever you want.

https://developer.roblox.com/api-reference/function/AnimationTrack/Stop

0
It says stop is not a valid member of animation. Shoohtin 4 — 4y
0
you should stop the loaded animation. not the animation. Thesquid13 301 — 4y
Ad

Answer this question