Animation plays infinitely when it should play once

basically, once the players health is above 16 the animation should play, once, but instead it loops infinitely
here is the script:

Hm.HealthChanged:Connect(function(health)
	if health >= 16 then
		GettingUpAnim:Play()
		local PlayerParts = Character:GetDescendants()	
		if Ragdolling.Value == true then
			for i,M6DBSC in pairs(PlayerParts) do
				if M6DBSC:IsA(SocketType) then
					M6DBSC:Destroy()
				elseif M6DBSC:IsA("Motor6D") then
					local parent = parents[M6DBSC.Name]
					if parent then
						M6DBSC.Parent = parent
					end
					wait()
					M6DBSC.DesiredAngle = Vector3.new(0, 0, 0)
					M6DBSC.DesiredAngle = 0
					M6DBSC.Enabled = true
				end
			end
			parents = {}
			HmHRP.CanCollide = true
			game.Workspace.CurrentCamera.CameraSubject = Character.Humanoid
			Hm:ChangeState(Enum.HumanoidStateType.GettingUp)
			Ragdolling.Value = false
		end
	end
end)

Make sure looped is unchecked… or

GettingUpAnim.Looped = false
1 Like

This function runs every time the player’s health changes, so as the player’s health increases the animation will be played every time. Maybe try adding a debounce.

Does the animation stop playing after the player gets full health? This would confirm that.

3 Likes

i know why its looped, i dont know how i should fix it, and a debounce would not be the solution

the animation isnt looped, its the Hm.HealthChanged:Connect(function(health)
thats looping it

the function is the loop, so yes it stops once health stops changing, but the loop is needed

You could do something like

local oldHealth = 100

Hm.HealthChanged:Connect(function(health)
	if oldHealth < 16 and health >= 16 then
		GettingUpAnim:Play()
		local PlayerParts = Character:GetDescendants()	
		if Ragdolling.Value == true then
			for i,M6DBSC in pairs(PlayerParts) do
				if M6DBSC:IsA(SocketType) then
					M6DBSC:Destroy()
				elseif M6DBSC:IsA("Motor6D") then
					local parent = parents[M6DBSC.Name]
					if parent then
						M6DBSC.Parent = parent
					end
					wait()
					M6DBSC.DesiredAngle = Vector3.new(0, 0, 0)
					M6DBSC.DesiredAngle = 0
					M6DBSC.Enabled = true
				end
			end
			parents = {}
			HmHRP.CanCollide = true
			game.Workspace.CurrentCamera.CameraSubject = Character.Humanoid
			Hm:ChangeState(Enum.HumanoidStateType.GettingUp)
			Ragdolling.Value = false
		end
	end

    oldHealth = health
end)

The animation would only play if the previous value of health is less than 16, but the new value is greater than or equal to 16.

2 Likes

i̶ ̶k̶n̶e̶w̶ ̶t̶h̶i̶s̶ ̶w̶o̶u̶l̶d̶ ̶h̶a̶p̶p̶e̶n̶ that breaks the script, the player doesnt get up once health is >= 16, which means the animation wont play

maybe add a value, check if the value is true before getting up, then set it to false?

local Downed = false --this would later get changed to True once the player is downed

   Hm.HealthChanged:Connect(function(health)
     if health >= 16 and Downed then
     Downed = false
     GettingUpAnim:Play()
    --rest of code

i didnt post the entire script but i have ragdolling value already, and its enabled at the end of the script
EDIT: here is what it looks like:

 local Ragdolling = Instance.new("BoolValue")

Ragdolling.Value = false

Ragdolling.Parent = Character

the ragdolled value already exist and its found here:

Hm.HealthChanged:Connect(function(health)
	if health >= 16 then
		GettingUpAnim:Play()
		local PlayerParts = Character:GetDescendants()	
		if Ragdolling.Value == true then
			for i,M6DBSC in pairs(PlayerParts) do
				if M6DBSC:IsA(SocketType) then
					M6DBSC:Destroy()
				elseif M6DBSC:IsA("Motor6D") then
					local parent = parents[M6DBSC.Name]
					if parent then
						M6DBSC.Parent = parent
					end
					wait()
					M6DBSC.DesiredAngle = Vector3.new(0, 0, 0)
					M6DBSC.DesiredAngle = 0
					M6DBSC.Enabled = true
				end
			end
			parents = {}
			HmHRP.CanCollide = true
			game.Workspace.CurrentCamera.CameraSubject = Character.Humanoid
			Hm:ChangeState(Enum.HumanoidStateType.GettingUp)
			Ragdolling.Value = false --right here is where its used
		end
	end
end)

yeah I noticed it, but you should put it next to if health >= 16 then, not make a different if statement in the first if statement
It’s the reason why the animation is playing infinitely

Try this:

Hm.HealthChanged:Connect(function(health)
	if health >= 16 and Ragdolling.Value == true then
        Ragdolling.Value = false --Put it first so it prevents animation playing infinitely
		GettingUpAnim:Play()
		local PlayerParts = Character:GetDescendants()	
			for i,M6DBSC in pairs(PlayerParts) do
				if M6DBSC:IsA(SocketType) then
					M6DBSC:Destroy()
				elseif M6DBSC:IsA("Motor6D") then
					local parent = parents[M6DBSC.Name]
					if parent then
						M6DBSC.Parent = parent
					end
					wait()
					M6DBSC.DesiredAngle = Vector3.new(0, 0, 0)
					M6DBSC.DesiredAngle = 0
					M6DBSC.Enabled = true
				end
			end
			parents = {}
			HmHRP.CanCollide = true
			game.Workspace.CurrentCamera.CameraSubject = Character.Humanoid
			Hm:ChangeState(Enum.HumanoidStateType.GettingUp)
		end
end)
1 Like