I want the script make the character to do the animation when activate tool
What is the issue?
Script completely doesnt work
Also I wont provide screenshot because its absolutely useless since script doesnt do anything
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.
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)
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