Issue with tools (scripting)

Hi, so I did the shield and the animation but it was supposed to show the tool on players had but it shows where is it built can someone tell me what to do to fix it?

robloxapp-20200903-1227121.wmv (146.0 KB) robloxapp-20200903-1223239.wmv (1.1 MB)

script.Parent.Equipped:Connect(function(Mouse)
	Mouse.Button1Down:Connect(function()
		animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation)
		animation:Play(5645979841)
	end)
end)

script.Parent.Unequipped:Connect(function()
	animation:Stop()
end)

The issue has been fixed thank you! :slight_smile:

2 Likes

Try this:

animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation.AnimationId)

script.Parent.Equipped:Connect(function(Mouse)
Mouse.Button1Down:Connect(function()
animation:Play()
end)
end)

script.Parent.Unequipped:Connect(function()
animation:Stop()
end)

If it doesn’t work please show me the errors in output.

1 Like

Thank u but the same thing happends

What are the errors in output?

this is what says with your script

The LocalScript is loading before the LocalPlayer’s Character has been added, you’ll want to Wait on CharacterAdded if it doesn’t exist:

local localPlayer = game:GetService("Players").LocalPlayer; --// GetService is the most canical way to retrieve services
local character = localPlayer.Character or localPlayer.CharacterAdded:Wait(); --// or logical operator chooses to run the second expression if the left hand is falsey

Additionally, the Humanoid may not be loaded yet and LoadAnimation takes an Animation Instance - not a AnimationId.

local animation = character:WaitForChild("Humanoid"):LoadAnimation(script.Parent.Animation);

Let me know how it goes.

The same thing thank u tho ) sdaweasdwa

Had an issue in my example, please again try now. This shouldn’t of been the same error?

Is the same thing but here is a pic I think that the model should be with the tool or to be the tool but it is under it.

Try something like
local tool = script.Parent
Local player = game.players.localplayer
Local anim = tool.Animation–add a animation and make it Animation also add a local script in the tool and put the animation under the local script.

tool.Equipped:Connect(function()
Animation:Play()
end

The problem may be you are writing these people’s scripts in the wrong place. Add a LocalScript to a Tool.

local animationid = 0
local humanoid = game.Players.LocalPlayer:WaitForChild("Humanoid")
local animation = Instance.new("Animation", humanoid)
animation.AnimationId = animationid
local track = humanoid:LoadAnimation(animation)
local tool = script.Parent
local equipped = false
tool.Equipped:Connect(function() equipped = true end)
tool.Unequipped:Connect(function() 
    equipped = false
    track:Stop()
end)
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button1Down:Connect(function()
    if not equipped then return end
    track:Play()
end)

There could be other problems. Like if the animation is R6 based and your testing it on a R15 character; The animation has no keyframes. Test this script with a different animation to see if it works. Then go back to your animation. If it doesn’t work with yours but it works with a different one, it could be your animation that is the problem.

You forgot to add character.

Kind of a late reply, but here I go.

On your last reply, I saw the error and it clearly says:

Players.KINGK_S.Backpack.Tool.Shield rig.LocalScript: attempt to index nil with 'Humanoid'

Usually if this error happens, that means the one before “Humanoid” is either a nil instance (something that doesn’t exist), or it’s an instance that does not contain a “Humanoid”. Since this Local Script is located in a tool and not in StarterCharacterScripts, it’s no more than a basis that the script runs before even the character of the player is added, so what you could do is to wait for the character:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

Another thing to note is that even if the character has loaded, there is a chance (it may vary, depending on the user’s/player’s connection) that even certain parts of the player’s character have not loaded yet. Quoting the humanoid. Which is why instead of using the dot syntax for finding the humanoid, what you instead could do is:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait() 
local humanoid = character:WaitForChild("Humanoid")

Obviously, as you can see from the method’s name itself, “WaitForChild” waits until the humanoid exists. It yields the whole thread, so this will prevent you from running into any whole-script-breaking errors.

Now that we have all that, the next likely thing we would want to do is for the humanoid to play animations. Usually for tools, I’d either just put the animation instance in ReplicatedStorage or ServerStorage. Although, LocalScripts cannot access ServerStorage, which is why it’s best to place it into ReplicatedStorage, or you could bundle it with the tool as well!

local animation = script.Parent.Anim_Name
local animtrack = humanoid:LoadAnimation(animation)

or:

local animation = Instance.new("Animation", character) --You can change character to wherever you want to put the animation instance to.
animation.Name = "WhateverYouWantTONameItHere"
animation.AnimationId = "rbxassetid://animIDhere"

local animtrack = humanoid:LoadAnimation(animation)

Once you have all that set, you can basically call animtrack:Play() to play the animation, and obviously, animtrack:Stop() to stop the animation. You can also keep it on looped by doing this:

animtrack.Looped = true

I’d also like to mention that the LocalScript should instead be parented to the tool instance, and not the tool’s handle.

Also, the method :LoadAnimation does not take animation IDs to play them. Rather, it takes an animation instance instead.

Anyways, I’d also like to give out a tip: If you want to get better at scripting, don’t just look at tutorials! Try to tweak with scripts, find out what they can do, and make your own twists! That’s how I did it. I slowly learn something new everyday. Hope I helped! :grinning:

1 Like

most of your points are correct but he can just place a local script in startercharacterscripts and just type local Humanoid = script.Parent.Humanoid this will be all on every client since its a starter character script

1 Like

I’m pretty sure I’ve also reminded him of that in my last post, but thanks as well. :hugs:

Either you haven’t created a part called handle inside your tool or the parts that compose your tool are unanchored.

This post is going to get deleted or cancelled if there hasn’t been a marked solution yet.