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

Play Animation when player pulls out tool not working?

Asked by 4 years ago

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:

Amim = Instance.new("Animation")
Amim.AnimationId = 04609133987
Amin.Parent = script.Parent.Parent

if script.Parent.Parent.Activated == true then
    Amim:play()
end

if script.Parent.Parent.Deactivated == true then
    Amim:stop()
end

1 answer

Log in to vote
1
Answered by 4 years ago

The animations has priority, use "Movement" and disable loop. The script must be "local"

local tool = script.Parent -- The tool that you're equipping
local Amim = Instance.new("Animation") -- you forgot "local" in here
Amim.AnimationId = 04609133987
Amin.Parent = script.Parent.Parent

local player = game.Players.LocalPlayer -- identifies the player user, works only with local script
local Humanoid = player.Character:WaitForChild(Humanoid) -- identifies humanoid for animation
local track = Humanoid:LoadAnimation(anim) -- loads animation

tool.Equipped:Connect(function()
track:play()
end)
tool.Unequipped:Connect(function()
track:Stop()
end)

To make animation work on equip you better use "Equipped:Connect()" You also have to load animation before playing it.

0
The script sits inside the Handle, it doesn't see, to work. Blxefirx 31 — 4y
0
put it outside the handle, or type in "local tool = script.Parent" this > "local tool = script.Parent.Parent" digameschannel 44 — 4y
Ad

Answer this question