Animation.Looped not being read correctly

I’m trying to make a taunt menu. There are 2 types of taunts in my game, the looping ones and the non-looping ones. I want the stopping system to change depending on whether or not they loop. For some reason, the looping animations are still registered as having .Looped disabled, though it is not.

Script:

local StarterGui = game:GetService("StarterGui")
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local AnimFolder = script.Parent.Anims
local Taunting = script.Parent.Parent.Taunting
local connection
local CanTaunt = true
local CurrAnim
local TauntSound

for i, v in pairs(script.Parent.Main:GetChildren()) do
	if v:IsA("TextButton") then
		v.MouseButton1Down:Connect(function()
			local TauntRequested = v.Name
			local SearchForTauntInLibrary = AnimFolder:FindFirstChild(TauntRequested)
			if SearchForTauntInLibrary ~= nil and CanTaunt then
				print("search succeeded")
				if CurrAnim ~= nil then
					CurrAnim:Stop()
					end
				CurrAnim = player.Character.Humanoid.Animator:LoadAnimation(SearchForTauntInLibrary)
				CurrAnim:Play()
				if CurrAnim.Looped == true then
					print("loopinganim")
					Taunting.Value = true
					script.Parent.Visible = false
					player.Character.Humanoid.WalkSpeed = 0
					if SearchForTauntInLibrary:FindFirstChild("IsMovingTaunt") then
						local sound = Instance.new("Sound")
						sound.Name = ("TauntSound")
						sound.SoundId = 'rbxassetid://9767287320'
						sound.Looped = true
						sound.RollOffMaxDistance = 250
						sound.RollOffMode = Enum.RollOffMode.InverseTapered
						sound.Parent = player.Character:FindFirstChild("HumanoidRootPart")
						sound:Play()
						end
					connection = UIS.JumpRequest:Connect(function()
						print("jrequest")
						if CurrAnim.IsPlaying then
							print("succeed")
							if player.Character:FindFirstChild("HumanoidRootPart"):FindFirstChild("TauntSound") then
								player.Character.HumanoidRootPart.TauntSound:Destroy()
							end
							CurrAnim:Stop()
							player.Character.Humanoid.WalkSpeed = 16
							Taunting.Value = false
							StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
							connection:Disconnect()
						end
					end)
				elseif CurrAnim.Looped == false then
					print("nonloop")
					Taunting.Value = true
					player.Character.Humanoid.WalkSpeed = 0
					script.Parent.Visible = false
					player.CameraMinZoomDistance = 8
					CurrAnim.Stopped:Wait()
					player.Character.Humanoid.WalkSpeed = 16
					Taunting.Value = false
					StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
					player.CameraMinZoomDistance = 0.5
				end
			end
		end)
	end
end

player.Character:WaitForChild("Humanoid").Died:Connect(function()
	print("Player has died; taunt logic stopping.")
	CurrAnim:Stop()
	CanTaunt = false
 	StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
	if player.Character:FindFirstChild("HumanoidRootPart"):FindFirstChild("TauntSound") then
		player.Character.HumanoidRootPart.TauntSound:Destroy()
	end
end)

Any help would be much appreciated!

2 Likes

Ok just to clarify:

You’re having a conditional statement where a script runs if your animation is looped

However it’s not reading the conditional statement correctly?

Yep!

[3O charssssssssssssssssssssssss]

Is your script local or server side?

try

elseif CurrAnim.Looped ~= true then

Everything is inside a LocalScript.

Nope, still doesn’t change anything!

Does the animation play generally?

If the animation doesn’t belong to you it will not work for any games under your name.

Yes it does, all of the animations are mine.

In your script where you put your variables it doesn’t seem like you’re referencing CurrAnim to anything.

Did you not put anything there intentionally?

Yes, it is nil until it is assigned an animation. It is assigned an animation before the check to see if it is looping, though.

It may be because there is no property ‘looped’?
If you used an animation property, that may be why.

There is a .Looped property on AnimationTracks. CurrAnim is being set to the animation instance that the taunt is. According to the link I previously sent, .Looped defaults to how it was set in the animation editor. All of the looping animations are looped in the animation editor. .Looped is indeed a real property.

Did you try running the script on a server script? In my game I have a humanoid NPC that plays an animation.

When running a conditional statement to check if it’s looped, it does come back true.

If you wouldn’t mind answering these questions as well:

-Where is the local script in order to check the animation located?
-Are there any errors in the output? If there are previous errors in your code it will prevent it from going forward

I have not tried a server script.

The LocalScript is in StarterGui, along with the animations (see tree below)
image

There are no errors.

Ok if you could try putting the code in a server script and coming back to the me that would be great

actually if you are referencing localplayer in that script it won’t work

Yeah, I was gonna use a RemoteEvent for all of that. It’d be kinda time consuming to make…

Hey there, since you’re loading your animation and using it right away it’s likely that the property hasn’t quite replicated yet. You can try adding a task.wait(.1) after you load the animtion, then print if the animation is looping or not. If this works you’ll need to allow for that slightly delay.

Nope, I added a wait and it still doesn’t make it work properly.