Hello, I was trying to make an Animation script that plays when a player pulls out a tool. I'm most likely to be using the wrong events.
Code:
01 | Amim = Instance.new( "Animation" ) |
02 | Amim.AnimationId = 04609133987 |
03 | Amin.Parent = script.Parent.Parent |
04 |
05 | if script.Parent.Parent.Activated = = true then |
06 | Amim:play() |
07 | end |
08 |
09 | if script.Parent.Parent.Deactivated = = true then |
10 | Amim:stop() |
11 | end |
The animations has priority, use "Movement" and disable loop. The script must be "local"
01 | local tool = script.Parent -- The tool that you're equipping |
02 | local Amim = Instance.new( "Animation" ) -- you forgot "local" in here |
03 | Amim.AnimationId = 04609133987 |
04 | Amin.Parent = script.Parent.Parent |
05 |
06 | local player = game.Players.LocalPlayer -- identifies the player user, works only with local script |
07 | local Humanoid = player.Character:WaitForChild(Humanoid) -- identifies humanoid for animation |
08 | local track = Humanoid:LoadAnimation(anim) -- loads animation |
09 |
10 | tool.Equipped:Connect( function () |
11 | track:play() |
12 | end ) |
13 | tool.Unequipped:Connect( function () |
14 | track:Stop() |
15 | end ) |
To make animation work on equip you better use "Equipped:Connect()" You also have to load animation before playing it.