Animation Script not working

Hi! I was working on this script right here, but I found a lot of errors in the output. The script is suppose to only happen when the player is running and is holding the boom box. I looked all over the internet before making this post to make sure I wasn’t making a simple mistake, but I couldn’t find a single thing relating to this issue. It should also have the boombox in hand when running the animation. I’m not really sure if that’s just added the second you run the animation or if you have to add it in using scripts. Here’s what the script looks like and heres my workspace:

local Anim = game.Players.Animation
if Enum.HumanoidStateType.Running and game.StarterPack.BoomBox.Equipped then
Anim:Play()
end

image

Please help!

Well there’s two problems here.

  1. You’re not contacting the Client’s tool. Instead, you are contacting the tool for all the Clients in the game through StarterPack. (Which isn’t necessarily a bad thing, but if it’s something you want the animation to play separately, then yeah it could be a problem.)

  2. The code is already being passed through after equipping the tool. Instead, why not just use an Equipped function?

For example, why not try:

local Tool = script.Parent

Tool.Equipped:Connect(function()
    --code
end)
1 Like

Seeing as the script is inside the tool, you might as well just do script.Parent
Also you’re not checking whether the player is walking correctly
It’s kind of messy though and a lot of unnecessary things, probably can be cleaned up

(the reason I’m using active = false/true is because I can’t use connect and ifs all in 1 statement, and it ends up automatically looping even when the tool becomes unequipped)

local player = game:GetService("Players").LocalPlayer
local active = false

script.Parent.Equipped:Connect(function()
	active = true
	player.Character.Humanoid.Running:Connect(function(speed)
		if speed > 0 and active == true then
			print("hi")
		else
			active = false
		end 
	end)
end)

It works though :slight_smile:

Hi! This does print hi when the dj is equipped and is walking. However, I don’t know how to load the animation :upside_down_face: I’ve looked up some tutorials on how to load the animations but it doesn’t work.

try putting the animation priority to something higher like Enum.AnimationPriority.Action

Where would I use that? I don’t think this code refrences enums.

Here’s an updated script, still doesn’t work though. I can’t get the animation to load into the player.

Capture

Perhaps try preloading the asset from the script instead of manually putting it in the properties.

you need to use
local animtrack = char.Animator:LoadAnimation()
animtrack:Play()

char is getting errors, how exactly do I fix that.

Alright, i’m terrible with animations via scripting. Can you possibly walk me through that?

Updated script, still doesn’t work:

Screenshot 2021-07-22 220616

char is referring to Player.Character

I actually stopped working on this yesterday. So I don’t think this post is needed anymore.