Animation Lenght

Hi! I made a script that will play animations, and I equip tool animation starts but I cant freeze it. I did try while loop to print the animation’s length but it prints 0.33… and when I put it inside wait() then it will stop when the animation did play. I did search on Roblox DevForum but I didn’t find anything.

Local Script:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local UserInputService = game:GetService("UserInputService")
local debouce = false
local ReplicatedStorage = game:WaitForChild("ReplicatedStorage")

repeat wait() until player.Character:WaitForChild("Humanoid")
local humanoid = player.Character.Humanoid

-- Animation
local startAnim = Instance.new("Animation")
local shootAnim = Instance.new("Animation")
local equipAnim = Instance.new("Animation")
local unequipAnim = Instance.new("Animation")
local nonstopAnim = Instance.new("Animation")

local Equiped = game:GetService("ReplicatedStorage"):WaitForChild("EQUIP."..game:GetService("Players").LocalPlayer.Name)
local HaveTorso = false

repeat
	if humanoid.RigType == Enum.HumanoidRigType.R15 then
		-- R15
		shootAnim.AnimationId = Equiped:WaitForChild("Animations"):WaitForChild("Animation15"):WaitForChild("Shoot").AnimationId
		equipAnim.AnimationId = Equiped:WaitForChild("Animations"):WaitForChild("Animation15"):WaitForChild("Equip").AnimationId

		print(player.Name..": Humanoid.RigType = R15")
		HaveTorso = true
	elseif humanoid.RigType == Enum.HumanoidRigType.R6 then
		-- R6
		shootAnim.AnimationId = Equiped:WaitForChild("Animations"):WaitForChild("Animation6"):WaitForChild("Shoot").AnimationId
		equipAnim.AnimationId = Equiped:WaitForChild("Animations"):WaitForChild("Animation6"):WaitForChild("Equip").AnimationId

		print(player.Name..": Humanoid.RigType = R6")
		HaveTorso = true
	else
		print(player.Name..": Humanoid.RigType = nil")
	end
	wait(0.0001)
until HaveTorso == true

local equipAnimS = humanoid:LoadAnimation(equipAnim)
local shootAnimS = humanoid:LoadAnimation(shootAnim)

local LP = game:GetService("Players").LocalPlayer

canAnim = true
if Equiped.EnableAnimation.Value == true then
	canAnim = true
else
	canAnim = false
end

Equiped.Event:Connect(function(player, message)
	if message == "EQUIPED" and canAnim then   -- In this If function is problem
		if not debouce then
			equipAnimS:AdjustSpeed(1)
			debouce = true
			equipAnimS:Play()
			
			while false do -- to print animation's length 
				print(equipAnimS.Length)
				wait(0.001)
			end
			
			wait(0.33) -- where I did put the animation's length to stop exactly when the animation stops
			equipAnimS:AdjustSpeed(0) -- to freeze animation
			debouce = false		
			
			print(LP.Name..": Lepic.EquipAnimation Played!")
		end
	elseif message == "SHOOT" and canAnim then
		if not debouce then
			debouce = true
			shootAnimS:Play()
			debouce = false
			
			print(LP.Name..": Lepic.ShootAnimation Played!")
		end
	elseif message == "UNEQUIPED" and canAnim then
		equipAnimS:AdjustSpeed(1) -- to unfreeze animation
		wait(0.3)
		
		print(LP.Name..": Lepic.UnEquipAnimation Played!")
	end
end)

Use :Stop() on Animation to stop the animation

Name the Animations differently.

Correct me if I’m wrong but, you could set up a keyframe on the last keyframe of your Equip Tool animation and then you could use KeyframeReached and freeze it, could even use:
https://developer.roblox.com/en-us/api-reference/function/AnimationTrack/GetTimeOfKeyframe

i have Animation: “EquipAnim”
And “EquipAnimS” (humanoid:LoadAnimation(EquipAnim)

1 Like

stop doesnt work I did try it before

1 Like
task.wait(Track.Length - 0.1)
Track:AdjustSpeed(0)

I’ve seen this solution work for others before but personally I’d use the ‘KeyframeReached’ event/signal to detect when a track’s keyframe is reached.
https://developer.roblox.com/en-us/api-reference/event/AnimationTrack/KeyframeReached

1 Like

Take a look at this Is it possible to freeze an animation in a pose while it is playing? - #2 by colbert2677