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!

tools replicate to characters and when you are referencing them in the starter pack it does nothing as it will never be equipped since it isnt on a player, you would refrence that character and then the tool in it. also you arent checking if the player is running just if Running exists which im pretty sure does nothing, also you should store animations in replicated storage and you need to :LoadAnimation() into the animator on the character to play them

1 Like


I used your information, I’m not really sure what to do if I’m being honest. I added the part where it defines the local player and their HumanoidStateType, but now it says Enum isn’t a part of players. I also moved the animation to ReplicatedStorage and changed Anim:Play() to Anim:LoadAnimation(). Still got errors from this.

i think you misunderstood my words or ri didnt word it correctly. To play animations you load them into the animator then play them
EX:
local animation = player.Character.Humanoid.Animator:LoadAnimation(theanimation)
animation:Play() to actual play the animation

also for the humanoid state if they are running you can do :GetState() on the humanoid as
if game.Player.LocalPlayer.Character.Humanoid:GetState() == Enum.HumanoidStateType.Running
and to tell if the boom box you would do
if game.Player.LocalPlayer.Character:FindFirstChild("BoomBox") then you reference the players boombox insted of the servers – edit - you would just check if the boombox is on the players character since if it is then it means its equipped

1 Like

Alright, yeah this makes a lot more sense now. I thought original I would have to define the player via local player to detect if they were running.

Where exactly would I put an if statement like this. Am I supposed to put it after the first if statement or before? Or do I put in the middle? This confuses me. Also here’s my workspace again:

image

Is your game also in a group? Maybe I can help with that.

It isn’t a group. You can use the script I provided to fix it though. I don’t really own any groups to begin with…

Instead of player.Character.Humanoid, I would suggest doing things as so:

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait() -- If the character doesn't exist, wait for it to be added.

local Humanoid = Character:WaitForChild("Humanoid")
local Animation = game:GetService("Players"):WaitForChild("Animation") -- Tbh, I have no idea why you're storing the animation in Players.
local AnimTrack = Humanoid.Animator:LoadAnimation(Animation)

if IsRunning and OtherConditions then-- If all your conditions are satisfied.. then.. (i didn't type all the requirements) 
 AnimTrack:Play()
end

How would I define IsRunning and OtherConditions?

I just added those to represent your requirements to play the animation, those aren’t required. In that line, all you need to do is check if all the conditions are met. Like the Humanoid | Roblox Creator Documentation has the Humanoid | Roblox Creator Documentation function which can be used to get the Humanoid’s current HumanoidStateType | Roblox Creator Documentation, and use that to check if it is running.