its a simple line of code and I don't understand why its not working.
01 | local tool = script.Parent |
02 | local player = game:GetService( "Players" ).LocalPlayer |
03 | local Ammo = script.Parent:WaitForChild( "Ammo" ) |
04 | local HoldAnimation = script.Parent.HoldAnim |
05 | tool.Equipped:connect( function (mouse) |
06 | print ( "Tool equipped!" ) |
07 |
08 | mouse.Button 1 Down:connect( function () |
09 | if Ammo.Value > = 1 then |
10 | print ( "Mouse pressed!" ) |
11 | Ammo.Value = Ammo.Value - 1 |
12 | HoldAnimation:Play() |
13 | print (Ammo.Value) |
14 | script.Parent.Handle.Fire:Play() |
15 | local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 300 ) |
it gives me and output that says 18:03:23.044 - Play is not a valid member of Animation
Okay so you need to load your animations into the humanoid using this function
1 | local C = player.Character |
2 | local Hum = C:WaitForChild( "Humanoid" ) |
3 | local PlayAnim = Hum:LoadAnimation(HoldAnimation) |
4 | PlayAnim:Play() |
-- Hopefully this helped!
You're on the right track! But, in order to play an animation, you have to first Load it onto the Humanoid.
The function Humanoid:LoadAnimation() is how you get an animation on a humanoid, ready to play. This function returns the AnimationTrack object, which is what you use :Play() on.
Example codes: (These use the LocalPlayer as a way of finding your player humanoid, so don't try and use the example copy-paste in anything but a Localscript.)
1 | humanoid = game.Players.LocalPlayer.Character.Humanoid |
2 | animTrack = humanoid:LoadAnimation(script.Parent.HoldAnim) |
3 |
4 | animTrack:Play() |
or:
1 | game.Players.Localplayer.Character.Humanoid:LoadAnimation(script.Parent.HoldAnim):Play() |
Link to AnimTrack properties on the wiki. Try messing with Playbackspeed!
Hope this helped.
Shoutout to @Mr_MilkysButler and @DropshitPilot's awesome ideas, try this:
1 | game.Players.PlayerAdded:connect( function (player) |
2 | repeat wait() until player.Character |
3 |
4 | local humanoid = player.Character.Humanoid |
5 | humanoid:LoadAnimation(HoldAnim) |
6 | HoldAnim:Play() |
7 |
8 | end ) |