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)