Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Animation Won't Play When The Mouse Clicks?

Asked by 4 years ago

So I am creating a simulator and most people know that when you are holding the tool or weapon and you click it plays and animation and gives strength. I am not focusing on the strength yet but I just need help on the animation. So the tool I am using is a wand and when you are holding it and you click, the animation will play. Everything is fine except for the animation. The animation won't play. The AnimationId is correct and and the animation is not nil. Everything but the "AnimationIsNil" is printing. I have moved some lines to other places and it still does not work. If any of you have a solution please tell me.

This is a local script in the StarterPlayerScripts

01local mouse = game.Players.LocalPlayer:GetMouse()
02local Character = game.Players.LocalPlayer.Character
03if not Character or not Character.Parent then
04    Character = game.Players.LocalPlayer.CharacterAdded:Wait()
05end
06local Humanoid = Character:WaitForChild("Humanoid")
07local Animator = Humanoid:WaitForChild("Animator")
08local WandMovement = Instance.new("Animation")
09WandMovement.AnimationId = "rbxassetid://6602046971"
10local Tool = game.Players.LocalPlayer.Backpack:FindFirstChildWhichIsA("Tool")
11 
12Tool.Equipped:Connect(function()
13    print("ToolEquippedFUnction")
14    mouse.Button1Down:Connect(function()
15        print("IntoMouseButtonFunction")
View all 24 lines...

Thank you for reading!

0
Also the priority of the Animation is Action MarcTheRubixQb 153 — 4y

2 answers

Log in to vote
1
Answered by
NGC4637 602 Moderation Voter
4 years ago
Edited 4 years ago

It will only play the animation when you equip and click at the same frame since it only fires the mouse click function when Tool equipped event is fired. So do this instead:

01debounce = false
02local Character = game.Players.LocalPlayer.Character
03if not Character or not Character.Parent then
04    Character = game.Players.LocalPlayer.CharacterAdded:Wait()
05end
06local Humanoid = Character:WaitForChild("Humanoid")
07local Animator = Humanoid:WaitForChild("Animator")
08local WandMovement = Instance.new("Animation")
09WandMovement.AnimationId = "rbxassetid://6602046971"
10local Tool = game.Players.LocalPlayer.Backpack:FindFirstChildWhichIsA("Tool")
11 
12Mouse.Button1Down:Connect(function()
13    if debounce = false then
14        debounce = true
15        if Character:FindFirstChild(""..Tool.Name) then
View all 33 lines...

I added debounce (cooldown) in case that was the problem.

0
Sorry, but this script sadly did not work. Thank you for trying to help me though! :) MarcTheRubixQb 153 — 4y
0
oof ok NGC4637 602 — 4y
0
OH MY GOD IM AN IDIOT I mispelled debounce to denounce lmao NGC4637 602 — 4y
0
there i fixed the typo NGC4637 602 — 4y
0
Ok I just figured out I needed to add one more thing and it worked! Thank you! MarcTheRubixQb 153 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Instead of

Animator:LoadAnimation(WandMovement)

you should try doing

Humanoid:LoadAnimation(WandMovement)

If this doesn't work, try changing the animation priority. I hope this helped!

0
I have tested it but it still has not work. Thank you leaving an answer to help me! :) MarcTheRubixQb 153 — 4y
0
Humanoid:LoadAnimation is deprecated. Animator:LoadAnimation is correct NGC4637 602 — 4y

Answer this question