Code issues "animations don't play"

Hello! My animations and all the code worked before, now I change all the local script code into one new localscript ( local script location was changed) and the animations no play, could someone help me see why that happens? what’s wrong with my code, please.

LOCALSCRIPT:

-- Input Services
local UIS = game:GetService('UserInputService')
local Player = game.Players.LocalPlayer
local Character = Player.Character

-- Declared
local intvalue = Instance.new("IntValue")
intvalue.Name = "Stamina"
local frame = script.Parent
local ydefault = 1

-- INPUTS AND STAMINA DECREASES SYSTEM

function RunAnimCall(rcall)
	if rcall then -- If started sprinting
		print("Started sprinting")
		intvalue.Value -= 15
	else -- Stopped sprinting
		print("Stopped sprinting")
	end
end

UIS.InputBegan:connect(function(input)--When a player has pressed LeftShift it will play the animation and it will set the normal walking speed (16) to 35.
	if input.KeyCode == Enum.KeyCode.LeftShift then
		Character.Humanoid.WalkSpeed = 35
		local Anim = Instance.new('Animation')
		Anim.AnimationId = 'rbxassetid://913376220'
		PlayAnim = Character.Humanoid:LoadAnimation(Anim)
		PlayAnim:Play()
		RunAnimCall(true) -- Calls RunAnimCall with rcall as true.
	end
end)

UIS.InputEnded:connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		Character.Humanoid.WalkSpeed = 16
		PlayAnim:Stop()
		RunAnimCall(false) -- Calls RunAnimCall with rcall as false.
	end
end)

-- STAMINA FUNCTIONS
-- Regen Stamina
intvalue.Changed:Connect(function()
	frame.Size = UDim2.new(intvalue.Value/100,0,ydefault, 0)
end)

intvalue.Value = 1
repeat 
	if intvalue.Value >= 0 then
		for i = 0, 100, 20 do
			intvalue.Value = i
			print("Your stamina percentage is: " .. intvalue.Value)
			wait(2)
		end
		print("Your stamina is complete")
		intvalue.Value = 1
	end
until intvalue.Value == 150


-- PLAYING ANIMS
-- LIGHT AND HEAVY HITS ARE THERE

-- Declared
local player = game.Players.LocalPlayer
repeat wait() until player.Character.Humanoid
local humanoid = player.Character.Humanoid
local stopAnim = player.Character
-- Defense animation
local defanim = Instance.new("Animation")
defanim.AnimationId = "rbxassetid://6233839018" --defend id 6233839018  --boxpose: 6234302765

-- Light hit animation
local light_hit_anim = Instance.new("Animation")
light_hit_anim.AnimationId = "rbxassetid://6234034921"

-- Concentrate hit animation
local con_hit_anim = Instance.new("Animation")
con_hit_anim.AnimationId = "rbxassetid://6233901250"

-- BoxPose
local boxpose = Instance.new("Animation")
boxpose.AnimationId = "rbxassetid://6234302765"

-- Input system
UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer

local c = false

game.Workspace.Tool.Handle.Touched:Connect(function() --tool touched
	-- Defense anim F key
	UserInputService.InputBegan:Connect(function(input, gameProccesedEvent)
		if input.KeyCode == Enum.KeyCode.F then
			print("Playing defense animation! done.")
			local playAnim = humanoid:LoadAnimation(defanim)
			playAnim:Play()
			script.DefAnim:FireServer()
		end
	end)

	-- Light attack anim with the left mouse click:
	local Debounce = false
	UserInputService.InputBegan:Connect(function(input, gameProccesedEvent)
		if not Debounce and input.UserInputType == Enum.UserInputType.MouseButton1 then
			Debounce = true
			print("Light attack activated")
			local playAnim = humanoid:LoadAnimation(light_hit_anim)
			playAnim:Play()
			script.LightHitAnim:FireServer()
			wait(0.5)
			Debounce = false
			c = true
			if c == true then
				print("Inside box pose")
				local playBoxPose = humanoid:LoadAnimation(boxpose)
				playBoxPose:Play()
				wait(5)
			end
		end
	end)

	-- Concentrate attack anim with the right mouse click:
	local Debounce = false
	UserInputService.InputBegan:Connect(function(input, gameProccesedEvent)
		if not Debounce and input.UserInputType == Enum.UserInputType.MouseButton2 then
			Debounce = true
			print("Heavy attack activated")
			local playAnim = humanoid:LoadAnimation(con_hit_anim)
			playAnim:Play()
			script.BigHitAnim:FireServer()
			wait(5)
			Debounce = false
		end
	end) -- End of tool touched	
end)

SERVERSCRIPT:

-- SERVER CONECCTION

-- Defense anim connected to server
game.StarterGui.Game.Background.StaminaBar.StamSystemAnims.DefAnim.OnServerEvent:Connect(function()
	print("Connected to defense anim.")
end)

-- Light hit anim connected to server
game.StarterGui.Game.Background.StaminaBar.StamSystemAnims.LightHitAnim.OnServerEvent:Connect(function(plr)
	print("Connected to light hit anim.")
	-- Damage functions
	local AttackDist = 10 --If a player is further than this value, they won't be damaged.

	for i,v in pairs(game.Players:GetChildren()) do --Loops through all players.		
		if v.Character ~= nil and plr.Character ~= nil and v ~= plr then --Checks if there's a character
			local pRoot = plr.Character:FindFirstChild("HumanoidRootPart")
			local vRoot = v.Character:FindFirstChild("HumanoidRootPart")

			if pRoot and vRoot and (plr.Character.HumanoidRootPart.Position - v.Character.HumanoidRootPart.Position).Magnitude < AttackDist then --Checks if the Root parts exist and if the player is in range.
				local Hum = v.Character:FindFirstChild("Humanoid")

				if Hum and Hum.Health > 0 then --Checks if player is alive.
					Hum.Health = Hum.Health - 10 --Change "100" to the damage the player should take.
				end
				--Stuff that happens when a player is in range.
			end
		end
	end
end)

-- Concentrate big hit anim connected to server
game.StarterGui.Game.Background.StaminaBar.StamSystemAnims.BigHitAnim.OnServerEvent:Connect(function(plr)
	print("Connected to concentrate hit anim.")

	-- Damage functions
	local AttackDist = 10 --If a player is further than this value, they won't be damaged.

	for i,v in pairs(game.Players:GetChildren()) do --Loops through all players.		
		if v.Character ~= nil and plr.Character ~= nil and v ~= plr then --Checks if there's a character
			local pRoot = plr.Character:FindFirstChild("HumanoidRootPart")
			local vRoot = v.Character:FindFirstChild("HumanoidRootPart")

			if pRoot and vRoot and (plr.Character.HumanoidRootPart.Position - v.Character.HumanoidRootPart.Position).Magnitude < AttackDist then --Checks if the Root parts exist and if the player is in range.
				local Hum = v.Character:FindFirstChild("Humanoid")

				if Hum and Hum.Health > 0 then --Checks if player is alive.
					Hum.Health = Hum.Health - 25 --Change "100" to the damage the player should take.
				end

				--Stuff that happens when a player is in range.
			end
		end
	end
end)

PLEASE I DON’T KNOW WHAT IS WRONG WITH MY CODE :frowning:

1 Like

I haven’t read it all as I don’t have the time but check the animation priority.

1 Like

I’ll be looking, I corrected everything that had to be corrected and it still doesn’t work … I’m not sure what it is exactly … I’ll keep looking

Are you sure that the Animation you’re trying to play is owned by you itself?

1 Like

Ye it’s, does i need to reupload it again?

No it isn’t necessary, but you can try debugging it by adding print statements, preferably in these lines:

UIS.InputBegan:connect(function(input)--When a player has pressed LeftShift it will play the animation and it will set the normal walking speed (16) to 35.
    if input.KeyCode == Enum.KeyCode.LeftShift then
        print("Something")
	    Character.Humanoid.WalkSpeed = 35
	    local Anim = Instance.new('Animation')
	    Anim.AnimationId = 'rbxassetid://913376220'
	    PlayAnim = Character.Humanoid:LoadAnimation(Anim)
	    PlayAnim:Play()
        print("Something v2")
	    RunAnimCall(true) -- Calls RunAnimCall with rcall as true.
    end
end)

I think there’s also a way to check if a animation has loaded? Let me look on the API real quick

1 Like

I uploaded the animations to roblox again and updated the id and still don’t work

I am not sure… still not working :frowning:

Were there any Output print statements at all?

Here didn’t enter
print("Heavy attack activated")

It did not enter in any condition where a key or mouse button is pressed

I might sound dumb here, but are your API Services enabled?

none of that is activated :frowning: should i activate everything?

That could potentially be 1 of the reasons? Just activate all of them, click Save, and run it again

The only other option I could think of is opening the Animation Editor again, and changing the all Animation Priority’s to “Action”

Remember that Humanoid:LoadAnimation() is deprecated

1 Like

I did that all and still not working :frowning: :sad:

Strange, even though Humanoid:LoadAnimation() is deprecated it still works, but I don’t think changing it would make much of a difference?

1 Like

Is this a group game? if it is then if you uploaded the animation asset as yours and copying isn’t enabled, then you will then need to upload the animation as the group.

sorry for bad explanation lol