Tool Script Error

What i’m picking up is when the player equips the tool, an animation will be on the player, upon unequipping it, the animation stops correct? If so simply do what I said above…

UserInputService.InputBegan:Connect(function(keyPressed, gameProcessed)
	if gameProcessed then return end
	if keyPressed.KeyCode = Enum.KeyCode.W then
		Animation:Play()
		repeat
		wait()
		until not UserInputService:IsKeyDown(Enum.KeyCode.W)
		Animation:Stop()
	end
end)

If the player is holding W, do the custom walk animation, if not holding, then don’t do the animation and the player will be idle.

No, that script doesnt work. (30 chars) You have to set the walk animation in a server script.
We want the player to walk like that until its unequipped, which also has to be set in a server script.

Holding W when the tool is equipped gives u the custom walk animation, basically. without the tool gives you the normal one. I’ll try it out,

This is what I normally used for the keys.

			game:GetService("UserInputService").InputBegan:Connect(function(Input, gameProcessed)
	if not gameProcessed then 
		if Input.KeyCode == Enum.KeyCode.W then 
					runtrack:Play()
					print("walking")
		end
	end
		end)
if script.Parent.Equipped == true then
game:GetService("UserInputService").InputEnded:Connect(function(Input, gameProcessed)
	if not gameProcessed then
		if Input.KeyCode == Enum.KeyCode.W then 
			runtrack:Stop()

Uh, you don’t even need that userinputservice then, you can just set the walk animation once the tool is equipped, and then just set the animation back to default once its unequipped.

if so, simply make a bool variable.

Script (or "Server"Script)

-- Make sure it's in ServerScriptService (SSS)
game.Players.PlayerAdded:Connect(function(player)
	local playertool = player:WaitForChild("Backpack"):WaitForChild("Bat"):WaitForChild("LocalScript") -- Change "Bat" to your tool name.
	local Animation = Instance.new("Animation", playertool)
	Animation.Name = "Run"
	Animation.AnimationId = "rbxassetid://1234567890" --Change to Animation Id
end)

LocalScript

local player = game.Players.LocalPlayer
local tool = script.Parent -- Make sure the local script is inside of the tool.
local equipped = false
local Animation = script.Run -- Place animation inside of script.
local runtrack = plr.Character.Humanoid:LoadAnimation(Animation)
tool.Equipped:Connect(function()
	equipped = true
end)
tool.Unequipped:Connect:(function()
	equipped = false
end)
UserInputService.InputBegan:Connect(function(keyPressed, gameProcessed)
	if gameProcessed then return end
	if not equipped then return end
	if keyPressed.KeyCode = Enum.KeyCode.W then
		runtrack:Play()
		repeat
		wait()
		until not UserInputService:IsKeyDown(Enum.KeyCode.W)
		runtrack:Stop()
	end
end)

The bool variable “equipped” lets us check if the weapon is equipped with

if not equipped then return end

basically saying, if the tool is not equipped, Don’t continue the following.
We set equipped when using

tool.Equipped:Connect(function()
	equipped = true
end)

And

tool.Unequipped:Connect:(function()
	equipped = false
end)

If you have any more questions feel free to ask.

Ok first off we have to use this piece of code.

player.Character.Animate.walk.WalkAnim.AnimationId = "rbxassetid://ANIMATIONIDHERE"

I moved the animation to a more suitable place.

Ah ok, just to let you know we change the default walk animation using this

player.Character.Animate.walk.WalkAnim.AnimationId = "rbxassetid://"

and then we just change it back to the default walk animation. Thats all we want, I already have a script thats working, and the script you sent failed.

If you change the AnimationPriority to Action, It most likely should not fail. If so what are the output errors.

EDIT: I also believe you can not redo setting the default walk animation, as they are owned by roblox and you can not set animations that are not owned by you or a group that your in.

@fastkingyaya What, I’ve never heard that before?
Hold on let me try something.

There are many topics about it…
https://devforum.roblox.com/t/can-we-share-animations-yet/17698
https://devforum.roblox.com/t/how-to-make-animations-public/54342/2

We have to use your method but did OP go to bed or something?

Didn’t, I’m just trying to figure this out right now

What’s confusing about it? I just adjusted the code as well I had a typo. Recopy it now and it should work.

Well, I’m not able to stop the run animation and the bat isnt there

External Media

Can I get a copy of the bat and scripts? It would allow me to help better as this topic has continued for quite some time.

Nevermind. I know why it didn’t stop, I had another error as well. Try to copy it again.

Thank you! But the bat does not appear, here is the scripts.

local script:
local plr = game.Players.LocalPlayer
local tool = script.Parent -- Make sure the local script is inside of the tool.
local equipped = false
local Animation = script:WaitForChild("Run") -- Place animation inside of script.
local runtrack = plr.Character.Humanoid:LoadAnimation(Animation)
tool.Equipped:Connect(function()
	equipped = true
end)
tool.Unequipped:Connect(function()
	equipped = false
end)
game:GetService("UserInputService").InputBegan:Connect(function(keyPressed, gameProcessed)
	if gameProcessed then return end
	if not equipped then return end
	if keyPressed.KeyCode == Enum.KeyCode.W then
		runtrack:Play()
		repeat
		wait()
			until not game:GetService("UserInputService"):IsKeyDown(Enum.KeyCode.W)
			runtrack:Stop()
	end
end)

serverscript:

game.Players.PlayerAdded:Connect(function(plr)			
	plr.CharacterAdded:Connect(function(char)
				
		local M6D = Instance.new("Motor6D", char.Torso)
		M6D.Name = "ToolGrip"
	        end)
	
game.Players.PlayerAdded:Connect(function(player)
	local playertool = player:WaitForChild("Backpack"):WaitForChild("Bat"):WaitForChild("LocalScript") -- Change "Bat" to your tool name.
	local Animation = Instance.new("Animation", playertool)
	Animation.Name = "Run"
	Animation.AnimationId = "rbxassetid://5522791201" end)
end)

The bat is a mesh part

The bat worked before correct?

Maybe you can try making an invisible part Named “Handle” Welding it to the mesh and rotating it as you please.

Also, Why are there two ends.

It did work before, but the bat did not get removed after unequipping so I removed that part

Also I did not know how to implement it with ur script

Try this. Make Part0 the “Handle” and Part1 the Mesh Inside a Weldconstraint.