Loop Animation not stopping

Hey, I ran into an issue while trying to make a campfire system using a proximity prompt, for some reason the looped sitting animation is being played 3x on the humanoid, the elseif function works fine, but it only stops the animation once, meaning the player would still have 2 sitting animations playing on loop. I tried to avoid it by adding a debounce, but it didn’t help at all.

Below you can see the code:

local SS = game.ServerStorage
local ProximityPrompt = script.Parent

ProximityPrompt.Triggered:Connect(function(Player)
	local PlayerData = SS.PlayerData[Player.Name]
	local Track = Instance.new("Animation")
	local Anim = Player.Character.Humanoid:LoadAnimation(Track)
	Track.AnimationId = "rbxassetid://8736821774"
	local UI = script.Campfire:Clone()
	local Debounce = true
	
	if Player and Player.Character then
		if PlayerData and not Player.Character:FindFirstChild("Deactivate") and Debounce then
			Debounce = false
			ProximityPrompt.MaxActivationDistance = 10
			Player.Character.HumanoidRootPart.CFrame = CFrame.lookAt(Player.Character.HumanoidRootPart.Position,script.Parent.Parent.Position)
			Player.Character.Humanoid.AutoRotate = false
			Player.Character.Humanoid.JumpPower = 0
			Player.Character.Humanoid.WalkSpeed = 0
			Anim:Play(.25)
			local anims = Player.Character.Humanoid.Animator:GetPlayingAnimationTracks()
			local Deactivate = Instance.new("Folder")
			Deactivate.Name = "Deactivate"
			Deactivate.Parent = Player.Character
			UI.Parent = Player.PlayerGui
			UI.Enabled = true
		elseif Player.Character:FindFirstChild("Deactivate") then
			Player.PlayerGui:FindFirstChild("Campfire"):Destroy()
			Player.Character:FindFirstChild("Deactivate"):Destroy()
			ProximityPrompt.MaxActivationDistance = 7
			local anims = Player.Character.Humanoid.Animator:GetPlayingAnimationTracks()
			for _,v in pairs(anims) do
				print(anims)
			end
			Anim:Stop(.25)
			Player.Character.Humanoid.AutoRotate = true
			Player.Character.Humanoid.JumpPower = 50
			Player.Character.Humanoid.WalkSpeed = 16
			Debounce = true
		end
	end
end)

This is how I figured out how many animations are being played on the character:

for _,v in pairs(anims) do
	print(anims)
end

This is what it prints:
multiple animations

Have you print to see if the conditions have been met?

Yes I have, I think the Anim:Stop(.25) doesn’t stop the animation for some reason.
Cause every time I use the proximity prompt, the print keeps adding one or two more animations to the list.
image
( This is how the print looks like after using the proximity prompt 3 times )

You should load the animation in the animator instead of the Humanoid.

you should load your animation in the animator

image

try this it should work

local SS = game.ServerStorage
local ProximityPrompt = script.Parent

ProximityPrompt.Triggered:Connect(function(Player)
	local PlayerData = SS.PlayerData[Player.Name]
	local Track = Instance.new("Animation")
	local Anim = Player.Character.Humanoid.Animator:LoadAnimation(Track)
	Track.AnimationId = "rbxassetid://8736821774"
	local UI = script.Campfire:Clone()
	local Debounce = true

	if Player and Player.Character then
		if PlayerData and not Player.Character:FindFirstChild("Deactivate") and Debounce then
			Debounce = false
			ProximityPrompt.MaxActivationDistance = 10
			Player.Character.HumanoidRootPart.CFrame = CFrame.lookAt(Player.Character.HumanoidRootPart.Position,script.Parent.Parent.Position)
			Player.Character.Humanoid.AutoRotate = false
			Player.Character.Humanoid.JumpPower = 0
			Player.Character.Humanoid.WalkSpeed = 0
			Anim:Play(.25)
			local anims = Player.Character.Humanoid.Animator:GetPlayingAnimationTracks()
			local Deactivate = Instance.new("Folder")
			Deactivate.Name = "Deactivate"
			Deactivate.Parent = Player.Character
			UI.Parent = Player.PlayerGui
			UI.Enabled = true
		elseif Player.Character:FindFirstChild("Deactivate") then
			Player.PlayerGui:FindFirstChild("Campfire"):Destroy()
			Player.Character:FindFirstChild("Deactivate"):Destroy()
			ProximityPrompt.MaxActivationDistance = 7
			local anims = Player.Character.Humanoid.Animator:GetPlayingAnimationTracks()
			for _,v in pairs(anims) do
				print(anims)
			end
			Anim:Stop(.25)
			Player.Character.Humanoid.AutoRotate = true
			Player.Character.Humanoid.JumpPower = 50
			Player.Character.Humanoid.WalkSpeed = 16
			Debounce = true
		end
	end
end)

Tried it just now, same result. Anything else I could try?

Same result, I tried it just now.

Can You show me the parent of that Proximity Prompt in Explorer and the Output

Just printing the parent like print(script.Parent.Parent)?

image

image
Unsure if I understood what you meant, but this is what I got.

1 Like

i don’t know how the campfires works but you want it to do something like this?

Yeah I did, it’s pretty close to what I was trying to do.

1 Like

Oh alright i hope this will help you

local SS = game.ServerStorage
local ProximityPrompt = script.Parent

ProximityPrompt.Triggered:Connect(function(Player)
	
	local PlayerData 	= SS.PlayerData[Player.Name]
	local Char		 	= Player.Character
	
	local Track 		= Instance.new("Animation")
	Track.AnimationId 	= "rbxassetid://8736821774"
	Track.Parent 		= Char
	
	local Anim 			= Player.Character.Humanoid.Animator:LoadAnimation(Track)
	local UI 			= script.Campfire:Clone()
	
	local Debounce 		= true

	if Player and Player.Character then
		
		if PlayerData and not Player.Character:FindFirstChild("Deactivate") and Debounce then
			Debounce = false
			ProximityPrompt.MaxActivationDistance = 10
			Player.Character.HumanoidRootPart.CFrame = CFrame.lookAt(Char:FindFirstChild("HumanoidRootPart").Position,script.Parent.Parent.Position)
			Player.Character.Humanoid.AutoRotate = false
			Player.Character.Humanoid.JumpPower = 0
			Player.Character.Humanoid.WalkSpeed = 0
			Anim:Play(.25)
			local anims = Player.Character.Humanoid.Animator:GetPlayingAnimationTracks()
			local Deactivate = Instance.new("Folder")
			Deactivate.Name = "Deactivate"
			Deactivate.Parent = Player.Character
			UI.Parent = Player.PlayerGui
			UI.Enabled = true
			
		elseif Player.Character:FindFirstChild("Deactivate") then
			
			Player.PlayerGui:FindFirstChild("Campfire"):Destroy()
			Player.Character:FindFirstChild("Deactivate"):Destroy()
			ProximityPrompt.MaxActivationDistance = 7
			local anims = Player.Character.Humanoid.Animator:GetPlayingAnimationTracks()
			for _,v in pairs(anims) do
				v:Stop()
			end
			Anim:Stop(.25)
			Player.Character.Humanoid.AutoRotate = true
			Player.Character.Humanoid.JumpPower = 50
			Player.Character.Humanoid.WalkSpeed = 16
			Debounce = true
			
		end
	end
end)

Thank you so much! The issue has now been fixed.

1 Like