My script is not working

Ok so, basically i made this localscript inside a tool to play an animation when the tool is activated, is something wrong with it?

local players = game:GetService("Players").LocalPlayer
local character = players.Character
local humanoid = character.Humanoid
local animation = script.Parent:WaitForChild("Animation")
local animator = humanoid:WaitForChild("Animator")
local loadAnim = animator:LoadAnimation(animation)

script.Parent.Equipped:Connect(function()
	loadAnim:Play()
end)

My workspace:
image

1 Like
local players = game:GetService("Players").LocalPlayer
local character = players.Character
local humanoid = character.Humanoid
local animation = script.Parent:WaitForChild("Animation")
local loadAnim = humanoid:LoadAnimation(animation)

script.Parent.Equipped:Connect(function()
	loadAnim:Play()
end)

Try this. And also you have id in Animation?

Yes i do have an id in the animation

Also there’s something inside the Humanoid called the Animator, i think that’s how you use it now because Humanoid:LoadAnimation is not working anymore for what i know

Why? I always use Loadanimation on Humanoid and all work’s fine.

I can’t find any error in your script, what problem you have?

It’s just not working, i don’t know what i can do to fix it

You just put all your variable in equipped function

try this:

local LocalPlayer = game.Players.LocalPlayer
local Humanoid = LocalPlayer.Character.Humanoid
local animation = script.Parent:WaitForChild("Animation")

script.Parent.Equipped:Connect(function()
	if Humanoid then
		local animator = Humanoid:FindFirstChildOfClass("Animator")
		if animator then
			local animationTrack = animator:LoadAnimation(animation)
			animationTrack:Play()
		end
	end
end)

Nope, still didn’t work for some reason.

So this might help, when i rename the “Handle” to anything else, i can’t collect it from the ground and it doesn’t stay in my hand when i hold it but when i equip it the animation playes itself over and over

local LocalPlayer = game.Players.LocalPlayer
local Humanoid = LocalPlayer.Character.Humanoid
local animation = script.Parent:WaitForChild("Animation")
local Cooldown = false
script.Parent.Equipped:Connect(function()
	if Humanoid then
		local animator = Humanoid:FindFirstChildOfClass("Animator")
		if animator and Cooldown == false then
			Cooldown = true
			local animationTrack = animator:LoadAnimation(animation)
			animationTrack:Play()
		end
	end
end)

script.Parent.Unequipped:Connect(function()
	Cooldown = false
end)
1 Like

Okay here is what happens: u play the animation when the tool is equiped, but because of the part called Handle, roblox gives u his tool pack including welding to the hand and the pick up animation which overrides yours

1 Like

So what you’re saying is that qPerfectionWeld is ruining the script?

1 Like

Just rename Handle to something else and use my code

1 Like

Yes that is a part of the solution, but now he need to weld the tool to his hands by himself

1 Like

For weld to hand you can use plugin or change weld for tool by yourself

1 Like

Ok, what plugin can i use for that?

1 Like

Tool grip editor. Or change with panel in properties
image

1 Like

How would that work, i have tool grip editor but what am i supposed to do?

1 Like