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)
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