This is the script i used:
local Tool = script.Parent local Player = game.Players.LocalPlayer Tool.Activated:connect(function() local animTrack = Player.Humanoid:LoadAnimation(script.Parent.Animation) animTrack:Play() end)
This is the error in the Output:
Players.Exonl_Roblox.Backpack.Sword.Script:5: attempt to index nil with 'Humanoid' - Server - Script:5
I am learning to script but i don't know what i did wrong
Help please.
This one should work V
local Tool = script.Parent local Player = game.Players.LocalPlayer Tool.Activated:Connect(function() local animTrack = Player.Character.Humanoid:LoadAnimation(script.Parent.Animation) animTrack:Play() end)
You forgot to index character. Humanoids are not parented to player objects. You can also find character by getting Tool's parent.
Humanoid:LoadAnimation() is deprecated by the way, you probably should use Animator:LoadAnimation() instead. (Animator is parented to Humanoid by default)
:connect() is also deprecated. I doubt there's any difference to be honest. The new one is :Connect(). Just so you know.
local Tool = script.Parent local Player = game.Players.LocalPlayer Tool.Activated:Connect(function() local Character = Tool.Parent local Humanoid = Character:FindFirstChild("Humanoid") if Humanoid ~= nil then local animTrack = Humanoid.Animator:LoadAnimation(script.Parent.Animation) animTrack:Play() end end)
You have to put "Player.Character.Humanoid" because, the humanoid is part of the character not the player.