Animation working on dummys but not on my character or on the character I'm pressing E to switch to

I made a Walk and Idle animations and I’m trying them, the Idle animation is working good everywhere even on my character but not on the character I’m pressing E to switch to, then also the walk animation which didn’t work anywhere only on the dummy.

here’s the script I have on the character I’m switching to for the 2 animations to play:

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")

local walkAnim = script:WaitForChild("Walk")
local walkAnimTrack = humanoid.Animator:LoadAnimation(walkAnim)

local idleAnim = script:WaitForChild("Idle")
local idleAnimTrack = humanoid.Animator:LoadAnimation(idleAnim)

humanoid.Running:Connect(function(speed)
	if speed > 0  then
		if not walkAnimTrack.IsPlaying and idleAnimTrack.IsPlaying then
			idleAnimTrack:Stop()
			walkAnimTrack:Play()
		end
	else
		if walkAnimTrack.IsPlaying and not idleAnimTrack.IsPlaying then
			idleAnimTrack:Play()
			walkAnimTrack:Stop()
		end
	end
end)