My Spear is animated and when its just in the workspace, i can pick it up and it does it's animation when it is clicked. However, i'm trying to put it in the StarterPack and it's not letting me do the animation. Here is the local script i used to play the animation:
local player = game:GetService("Players").LocalPlayer local character = player.character local animation = script.Parent:FindFirstChild("Stab") local swingAnimation = character.Humanoid:LoadAnimation(animation) local canswing = true local debounce = 1 script.Parent.Activated:Connect(function() if canswing then canswing = false swingAnimation:Play() wait(debounce) canswing = true end end)
Also, the error message says: Players.LegoDan0101.Backpack.Rusty Spear.LocalScript:4: attempt to index nil with 'Humanoid'
Theres your answer.
-- Alright heres an answer local player = game:GetService("Players").LocalPlayer local character = player.character local animation = script.Parent:FindFirstChild("Stab") local swingAnimation = character.Humanoid:LoadAnimation(Animation) -- here mispelling (fixed) local canswing = true local debounce = 1 script.Parent.Activated:Connect(function() if canswing then canswing = false swingAnimation:Play() wait(debounce) canswing = true end end)
I'm pretty sure that LoadAnimation is deprecated. If it helps, try using animator.
read up here: https://developer.roblox.com/en-us/api-reference/class/Animator
local player = game:GetService("Players").LocalPlayer local character = player.character local animation = script.Parent:FindFirstChild("Stab") local animator = character.Humanoid.Animator -- gets the animator of the humanoid local animationtrack = animator:LoadAnimation(animation) -- loads the animation local canswing = true local debounce = 1 script.Parent.Activated:Connect(function() if canswing then canswing = false animationtrack:Play() -- plays the animation wait(debounce) canswing = true end end)
I have worked it out, for anyone else with the same problem, here was my final code for this.
wait () local player = game.Players.LocalPlayer local character = player.Character if not character or not character.Parent then character = player.CharacterAdded:wait() end local character = game.Players.LocalPlayer.Character local animation = script.Parent:FindFirstChild("Stab") local humanoid = character:FindFirstChildWhichIsA("humanoid") local player = humanoid and game.Players:GetPlayerFromCharacter(humanoid.Parent) local swingAnimation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(animation) local animator = character.Humanoid.Animator local canswing = true local debounce = 1 script.Parent.Activated:Connect(function() if canswing then canswing = false swingAnimation:Play() wait(debounce) canswing = true end end) local pl = workspace:FindFirstChild("Player") if pl then local hum = pl:FindFirstChild("Humanoid") if hum then hum.Health = 0 end end