Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Play Animation when player pulls out tool not working?

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

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.

2 comments

0

The script sits inside the Handle, it doesn't see, to work.

0

put it outside the handle, or type in "local tool = script.Parent" this > "local tool = script.Parent.Parent"

This discussion is preserved as it was. New answers, comments, and votes are closed.