I need some help, I have a script where I'm trying to set a custom walk and idle animation while a tool is equipped

The action ID seems to work fine, but I’m not able to set the idle/walk id. Not sure why.

local walkID = "http://www.roblox.com/asset/?id=6085402599" --6094470765
local idleID = "http://www.roblox.com/asset/?id=6085409864"
local actionID = "http://www.roblox.com/asset/?id=6085354892"

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local event = ReplicatedStorage:WaitForChild("Animations")

local debounce = false

local equipped = false
local animate

script.Parent.Equipped:Connect(function()
	local animate = script.Parent.Parent.Animate
	equipped = true
	
end)

script.Parent.Unequipped:Connect(function()
	equipped = false
	animate.walk.WalkAnim.AnimationId = "http://www.roblox.com/asset/?id=913402848"
end)

script.Parent.Activated:Connect(function()
	if script.Parent.Equipped and debounce == false then
		debounce = true
		local humanoid = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid")
		local action = Instance.new("Animation")
		action.AnimationId = actionID
		local track = humanoid:LoadAnimation(action)
		track:Play()
		track.Stopped:Wait()
		wait()
		debounce = false
	end		
end)
1 Like

humanoid:LoadAnimation is deprecated, so you should load animation on the animator instead. You can create an animator by using Instance.new(“Animator”) or reference it from the humanoid: local animator = humanoid:FindFirstChildOfClass("Animator")

Heya, could you please let me know where in the script I should add this line? I’m still pretty new.

He is telling that to find animations, you can use FindFirstChildOfClass instead of FindFirstChild.

Well, you would need to replace humanoid:loadAnimation() with animator:LoadAnimation().
You seem to have two walk animations so I’m not too sure which one you want to incorporate or how you’re implementing your other animations.

script.Parent.Unequipped:Connect(function()
	local humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
		local WalkAnim = Instance.new("Animation")
		WalkAnim.AnimationId = "http://www.roblox.com/asset/?id=913402848"
		if humanoid then
			local animator = humanoid:FindFirstChildOfClass("Animator")
			if animator then
			local animationTrack = animator:LoadAnimation(WalkAnim)
			animationTrack:Play()
		end
	end
end)

script.Parent.Activated:Connect(function()
	if script.Parent.Equipped and debounce == false then
		debounce = true
		local humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
		local action = Instance.new("Animation")
		action.AnimationId = actionID
		if humanoid then
		local animator = humanoid.Animator
		if animator then
			local track = animator:LoadAnimation(action)
			track:Play()
			track.Stopped:Wait()
			wait()
			debounce = false
			end
		end
	end
end)

What you basically need to know is that you need to utilise the Animator to load and play the animations instead. An example code snippet from the Developer API Reference:

local animator = humanoid:FindFirstChildOfClass("Animator")
if animator then
    local animationTrack = animator:LoadAnimation(Animation)
    animationTrack:Play()
    return animationTrack

[quote=“Xx_FROSTBITExX, post:5, topic:930894”]


Thanks man! Sorry, the other walk anim was a mistake.
3 Likes