Here is the working script for anyone who was wondering or wants to know how I solved this. It took me a long time, at first I didn't understand! Here's a link that helped me!

https://developer.roblox.com/en-us/api-reference/function/Humanoid/GetPlayingAnimationTracks I also recommend testing my code below if you're new.

This is a LocalScript in StarterGui.

local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local cas = game:GetService("ContextActionService")

local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://27789359"

function OnKeyPressed(actionName, inputState, inputObject)
	if inputState == Enum.UserInputState.Begin then
		humanoid:LoadAnimation(animation):Play()
wait(10)--or do whatever you want here really
local animationTracks = humanoid:GetPlayingAnimationTracks()
		for _, v in pairs(animationTracks) do
			v:Stop()
	end
end

cas:BindAction("PlayAnim", OnKeyPressed, true, Enum.KeyCode.Q)
cas:SetPosition("PlayAnim", UDim2.new(1, -70, 0, 10))

1 comment

0

Sorry about the links, I tried using the link button and it posted like this.