How do I make a tool that plays animation and music when equipped, but then everything ends when I unequip it.
(Note: I am sorry if I did something wrong with the post I just recently made, I’m new to the forum so I am not used to doing this ;-
How do I make a tool that plays animation and music when equipped, but then everything ends when I unequip it.
(Note: I am sorry if I did something wrong with the post I just recently made, I’m new to the forum so I am not used to doing this ;-
You would need to use Tool.Equipped
for whenever the emote needs to be played, then you’d use Tool.Unequipped
for when you want them to stop emoting.
You would need to create an animation, and then move the animation to the player, and on the Tool.Equipped
function, just play the animation.
Here’s a basic script that will play any given animation and sound when it is equipped, and will stop them when the tool is unequipped (assuming that the sound and/or animation are still playing).
Put this inside of a LocalScript that is inside of the desired tool.
local tool = script.Parent
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
local humanoid = character:WaitForChild("Humanoid")
local animation = --animation location here
local sound = --sound location here
local animtrack;
function ToolEquipped()
animtrack = humanoid:LoadAnimation(animation.AnimationId)
animtrack:Play()
sound:Play()
end
function ToolUnequipped()
if animtrack.IsPlaying then
animtrack:Stop()
end
if sound.Playing then
sound:Stop()
end
end
tool.Equipped:Connect(ToolEquipped)
tool.Unequipped:Connect(ToolUnequipped)
Hope this helped!
what do you mean by “local animtrack;”
It’s just a variable that havent been given a value yet and its nil
local animtrack;
is an undefined variable that is later on defined when the function ToolEquipped()
is called. If you’d like to change it to be more comprehensive, you can do this:
local animtrack = humanoid:LoadAnimation(animation.AnimationId)
function ToolEquipped()
animtrack:Play()
sound:Play()
end
Either way, the same effect is achieved.