Animation wont play

I am trying to make it o that when my tool is equipped and I press my Left Mouse Button is clicked an animation plays. But there are no errors but the animation does not play. Can anyone help.
Thank You!!

Local Script

local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local Dumbbell = game.StarterPack.Dumbbell
local player = Players.LocalPlayer
local character = player.Character

if not character or not character.Parent then
	character = player.CharacterAdded:Wait()
end

local function onInputBegan(input, gameProcessed)
	if Dumbbell.Equipped and input.UserInputType == Enum.UserInputType.MouseButton1 then
		local humanoid = character:WaitForChild("Humanoid")
		local animator = humanoid:WaitForChild("Animator")

		local liftAnimation = Instance.new("Animation")
		liftAnimation.AnimationId = "rbxassetid://6988682446"

		local liftAnimationTrack = animator:LoadAnimation(liftAnimation)

		liftAnimationTrack:Play()
		wait(3)
		liftAnimationTrack:Stop()
	end
end

UserInputService.InputBegan:Connect(onInputBegan)
1 Like

Is the animation yours?

ignore this

Yup it is. :slightly_smiling_face:

Is the animation priority action?

1 Like

No. :expressionless: I did not think it will need

Yeah, for it to be visibly been shown the priority has to be higher than the idle and any character animation.

Lemme fix that just about 5 mins.

Thank you so much it works now.

But the animation still plays even when the dumbbell is not equipped.

Your “if Dumbbell.Equipped” has no use as of now, you have to let the script know if it’s true or not, by using an equal to operator.

I edited your line.

if Dumbbell.Equipped == true and input.UserInputType == Enum.UserInputType.MouseButton1 then
1 Like

sorry gtg :expressionless: mmmmm

if Dumbbell.Equipped then and if Dumbbell.Equipped == true then basically do the same thing.

if you wanted to check if it wasn’t true you would do

if not Dumbbell.Equipped then

But I assume you don’t have a boolean for it yet, you should make a boolean in the script to let the script know if the tool is equipped or not using .Equipped and .Unequipped events.

Sample script:

equip = false --Boolean we will use for the check.

game.Players.LocalPlayer.Backpack.Dumbell.Equipped:Connect(function()
     equip = true
end

game.Players.LocalPlayer.Backpack.Dumbell.Unequipped:Connect(function()
     equip = false
end

And I noticed that the Dumbbell variable you assigned is assigned to StarterPack instead of the player’s actual backpack, you can fix this by pathing to LocalPlayer.Backpack.Dumbbell instead of the StarterPack, the StarterPack is what will be cloned to player’s backpacks. Not the local player’s backpack.

Just figured it’s not an actual property… refer to my last reply-

1 Like

Ok i’ll try this and see if it works.

I don’t really get what to do here. @Wynsage

(post marked for deletion for privacy reasons)

1 Like

We are done with all this I just want a confirmation that the tool is equipped before the animation plays.

Oh, basically you will have to adapt it in your current script. Mine was just an example on how to do the events and booleans.

Let me edit your script.

local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character
local Dumbbell = player.Backpack.Dumbbell
equip = false

if not character or not character.Parent then
	character = player.CharacterAdded:Wait()
end

Dumbell.Equipped:Connect(function()
     equip = true
end

Dumbell.Unequipped:Connect(function()
     equip = false
end

local function onInputBegan(input, gameProcessed)
	if equip == true and input.UserInputType == Enum.UserInputType.MouseButton1 then
		local humanoid = character:WaitForChild("Humanoid")
		local animator = humanoid:WaitForChild("Animator")

		local liftAnimation = Instance.new("Animation")
		liftAnimation.AnimationId = "rbxassetid://6988682446"

		local liftAnimationTrack = animator:LoadAnimation(liftAnimation)

		liftAnimationTrack:Play()
		wait(3)
		liftAnimationTrack:Stop()
	end
end

UserInputService.InputBegan:Connect(onInputBegan)

There you go, I transitioned my script into yours. Let me know how it goes. :slightly_smiling_face:

1 Like

Oops, edited. Messed up something with the script.