My Animated tool isn't working?

  1. What do you want to achieve? Keep it simple and clear!
    I want to figure out how i can make my animated tool work.

  2. What is the issue? Include screenshots / videos if possible!
    I was coding an animated tool, but the animations dont play.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I first just tried using a WaitForChild(“TehEpicViking”) for testing but after i did it for when the tool’s parent isn’t the workspace it broke the code

local tool = script.Parent.Parent
local ToolActivated = false

local random2 = "6494653927"
local random1 = "6494627139"
local Randoid = random1

local function RandomId()
	if Randoid == random1 then
		Randoid = random2
	else
		Randoid = random1
	end
end

if tool.Parent.Name ~= "Workspace" then
	local player = tool.Parent
	local humanoid = player:FindFirstChild("Humanoid")
	local animation = Instance.new("Animation")
	animation.AnimationId = "http://www.roblox.com/asset/?id=6494618583"

	local animationTrack = humanoid:LoadAnimation(animation)
	
	tool.Equipped:Connect(function()
		animationTrack:Play()
	end)
	tool.Unequipped:Connect(function()
		animationTrack:Stop()
	end)
 
	tool.Activated:Connect(function()
		if ToolActivated == false then
			ToolActivated = true
			RandomId()
			local activateanimation = Instance.new("Animation")
			activateanimation.AnimationId = "http://www.roblox.com/asset/?id="..Randoid
			
			local animationtrackthe2nd = humanoid:LoadAnimation(activateanimation) 
			animationtrackthe2nd:Play()
			wait(1.2)
			ToolActivated = false
		end
	end)
end

Also, there are no errors in the output, so i don’t really know whats happening

also this is my first time using animations and the code is kinda messy

Make sure you set the animationtrack’s .Priority to Enum.AnimationPriority.Action
If that doesn’t work, then import the original animation, use animation editor to set that animation’s priority to action, and export

What is the script parented to?

I found that this didn’t work for me. I had to manually, in the animation editor, make it an action priority.

Why are you loading multiple animations. You are loading animations here for some reason:

then load more here

Can you explain?

I already set all of the animation’s priotrities

One is for the idle, and the other is for the attack animation

Its parented to the workspace.

Can you explain the order things happen. Because, it loads a random animation, then when tool.Activated is fired, you load another another animation (which is the animation you want to play I assume) is this correct? If it is, then try printing the animation’s priority. This will say if it is overlapped by other animations. For instance, A Core (lowest priority) animation will be overlapped by an idle animation. And an idle animation will be overlapped by a moving animation. Lastly, a moving animation will be overlapped by an action animation. This is something that is crucial. This is because, if your animation has priority set to Core, then it will be overlapped by anything. Also, I recommend to load the animation when you equip the tool. This will make it so that the animation only has to run when it is activated.

If the script is parented to the workspace then how does the tool become the script’s parent.parent?

The tool is, not the script, the script is inside of the handle, which is parented to the tool, to the workspace

How it works is it sets an animation an animation track for the IDLE, but I haven’t played it yet. When the tool is EQUIPPED, it plays the animtrack. when its UNEQUIPPED, it stops it, when its ACTIVATED, it creates a new anim and animtrack and plays it once

I dont think its the priority, i think its just the humanoid, character, or player.

when i use a game.Workspace:waitforchild(“TehEpicViking”), it works, but when i try getting the character by the tool parent, it breaks

Are your animations for r6 or r15?

R15, all of the animations are R15.

Try making that track and loading it to the humainoid when you equip the tool. This is so that it doesn’t need to create a track. Then play the animation it when it is clicked.

Ill try that, thank you for helping!

also, another thing. when i try to find a character using waitforchild(),the code WORKS, but when i want to make it usuable for other people, it breaks

this is what it looks like when I use waitforchild()

BUT it only works for my character, any other character will not be able to use it

What is the part you are yielding for?

is this a local or server script?