Still have questions? Join our Discord server and get real time help.
0

# How do I make a script in a tool that makes the tool play a animation once I equip it?

I have a tool in game.StarterPack I want it to play a animation once I equip it. I made a r6 animation and the game is r6. I have the animation in the tool. I do not know if I should use a server script or a local script. But, I made a server script that does not work. Here it is:

local animation = script.Parent.Animation

if script.Parent.Equipped == true then
local animation:Play()
end


0
Equipped is an event, not a boolean theking48989987 1853 — 6d
0
Sorry, I did not know that. Please tell me what I can do. AwesomeMrBird -29 — 6d
0
Are you askng, like how to make a equip animation script? Like the way you hold the tool? or what? And also, as theking said, Equipped is an event. ChefDevRBLX 36 — 6d
0
ChefDev, what I mean is when I take out the tool it plays an animation. AwesomeMrBird -29 — 5d

0
pidgey 443
5 days ago
Edited 5 days ago

Equipped is an event. You can't compare Equipped (which is RBXScriptSignal) to a boolean value. Instead, connect it to a function so that when the event fires, the function is ran. You can connect an event to a function by using the Connect method in a RBXScriptSignal. Remember that you also can't play an animation if it's built on R15 and you're using an R6 rig.

local player = game.Players.LocalPlayer --this is the Local Player. only local script's can reference the Local Player.
local character = player.Character or player.CharacterAdded:wait() --if the Character is nil than the script will wait for the character to be added
local humanoid = character:WaitForChild("Humanoid") --wait for the humanoid to be added to the character before we try and reference it

local tool = script.Parent
local animation = tool.Animation

tool.Equipped:Connect(function() --connect event to function
wait(0.1) --allow some time. roblox doesn't like it when you play an animation immediately after this event apparently
track:Play() --play the animation
end)
tool.Unequipped:Connect(function()
track:Stop() --stop the animation in case the player unequips the tool while the equip animation is playing. counter-measure
end)


I tried to be descriptive on what was happening. It's good practice to use lots of descriptive variables. Good luck!

0
How do I make the player frozen during the animation? AwesomeMrBird -29 — 5d
1
sheepposu 127
6 days ago

You can do this

local animation = script.Parent.Animation
local animation_time-span = 1 --seconds
local tool = script.Parent

script.Parent.Equipped:Connect(function()
local humanoid = game.Players.LocalPlayer.Character:WaitForChild('Humanoid') --get humanoid (use LocalScript for this)
humanoid = tool.Parent:WaitForChild('Humanoid') -- get humanoid (script, not localscript)
track:Play()
wait(animation_time-span)
track:Stop()
end)


Remove the wait and stop and it will play continuously

0
I want a script that once I take out the tool from my backpack it plays an animation. The animation is in the tool. AwesomeMrBird -29 — 5d
0
Your variable at line 2 is a syntax error. You don't need to load the animation into the humanoid every time it's equipped - initialize it in the global scope. pidgey 443 — 5d
0
??? AwesomeMrBird -29 — 5d
0
The problem is, what if the tool doesn't start in a player. What if the tool switches players, like a trade sheepposu 127 — 5d