The tool animation script doesn't work

  1. What do you want to achieve?

I want the script make the character to do the animation when activate tool

  1. What is the issue?

Script completely doesnt work
Also I wont provide screenshot because its absolutely useless since script doesnt do anything

  1. What solutions have you tried so far?

I looked on devforum, but I didnt find anything helpful

Its my first time using animations or tools so that’s why I have this issue

local anim = script.rockAnimation
local player = game.Players.LocalPlayer
if player:IsDescendantOf(game.Players) then
	local tool = player.Backpack.rock
	local char = player.Character
	local hum = char.Humanoid
	local animtrack = hum:LoadAnimation(anim)
	tool.Equipped:Connect(function()
		local newtool = char.rock
		newtool.Activated:Connect(function()
			animtrack:Play()
		end)
	end)
end

And lastly the error code I get: Backpack is not a valid member of Player “Players.Super_Boris2011” - Client - rockscript:4

P.S. I know that I have to do animations in Server Scripts, but I was just testing so I didnt do that.

Thanks.

edited, removed unnecessary lines and the problem is with the way you were indexing the tool

do it like this:

local anim = script.rockAnimation
local player = game.Players.LocalPlayer

local tool = script.Parent -- use a direct path to the tool
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local animtrack = hum:LoadAnimation(anim)

tool.Activated:Connect(function()
	animtrack:Play()
end)

assuming the tool is the parent of the script

Okay, i will try that, but can you explain a bit why you changed the char variable to this? I just never saw anyone doing that and idk what it means

It didnt work and it made a new error - Activated is not a valid member of PlayerScripts “Players.Super_Boris2011.PlayerScripts”

gets the character, and incase the player’s character doesn’t exist, it waits until the character is spawned.

1 Like

no dude the script should be placed inside the tool

Oh okay thank you for explaining.

1 Like

Oh, okay, I will try that, hope it works.

I got a new error - rockAnimation is not a valid member of LocalScript “Players.Super_Boris2011.Backpack.rock.rockscript”

I had this error before too, when testing, even when the animation object is actually child of LocalScript

oh i c, try this:

local anim = script:WaitForChild("rockAnimation")
local player = game.Players.LocalPlayer

local tool = script.Parent -- use a direct path to the tool
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local animtrack = hum:LoadAnimation(anim)

tool.Activated:Connect(function()
	animtrack:Play()
end)

added: WaitForChild("rockAnimation"), WaitForChild("object") will wait for the object to get added just incase it hasn’t loaded in

1 Like

Yay, thank you so much! It worked!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.