Animation Spamming

I’m pretty new to animations and I’ve been running into this error where my animation rapidly spams over and over again. Any help would be much appreciated. Heres a gif of the error: https://gyazo.com/39d2a6591eaa941d7f0ee843d7a6896d

Code: (Event)

if Action == "Stun" then
		
		if Player.Settings.Stunned.Value == true then
			
			local Humanoid = Player.Character.Humanoid
			
			Player.PlayerGui.Main.Injured.Visible = true
			Player.PlayerGui.Main.Injured.Ringing:Play()
			

			
			local Animation1 = Instance.new("Animation")
			Animation1.AnimationId = "http://www.roblox.com/asset/?id=11904281956"
			
			local Animation2 = Instance.new("Animation")
			Animation2.AnimationId = "http://www.roblox.com/asset/?id=11904390771"
			
			local AnimationTrack1 = Humanoid:LoadAnimation(Animation1)
			local AnimationTrack2 = Humanoid:LoadAnimation(Animation2)
			
				AnimationTrack1:AdjustSpeed(0.25)
				AnimationTrack1.Looped = false
				AnimationTrack1:Play()
			AnimationTrack1.Stopped:Wait()
			
				Humanoid.WalkSpeed = 0

				AnimationTrack2.Looped = true
				AnimationTrack2:AdjustSpeed(0.25)
				AnimationTrack2:Play()
			
			Player.Character.Humanoid.HealthChanged:Connect(function()
				if Player.Character.Humanoid.Health >=40 then
					for _,anim in pairs(Humanoid.Animator:GetPlayingAnimationTracks()) do

						anim:Stop()
						Humanoid.WalkSpeed = 22
					end

			
				end
				end)
	
			
			
			
			
			
			
			
			
			
			
			
			
		end
		
		
	end

Try disabling looped for the 2nd animation. Sometimes you need to wait for it to load before using Stopped.

This might possibly be whatever is firing the event.

Still not working unfortuantely.

This is whats firing the event(LocalScript in StarterCharacterScripts):

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local Humanoid = Character.Humanoid

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EventsFolder = ReplicatedStorage.Events
local StunEvent = EventsFolder.Stun

local RunService = game:GetService"RunService"
local UserInputService = game:GetService"UserInputService"

local debounce = false

Humanoid.HealthChanged:Connect(function()
	if Humanoid.Health <=25 and debounce == false then
		debounce = true
		StunEvent:FireServer("Stun")
		Player.PlayerScripts.CursorControl.Enabled = false
		
		
	elseif Humanoid.Health >=40 then
		debounce = false
		StunEvent:FireServer("Unstun")
		Player.PlayerScripts.CursorControl.Enabled = true
		
	end
end)

I’ve had issues with HealthChanged where it fires rapidly for no apparent reason. You should add a check for the server to make sure the health is where you want it before running the function.

1 Like

Go to the animation and turn off the little loop button,
you have the animation set to loop, if you dont have the anim saved then u gotta redo it and not hit the loop button

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.