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
It does not work, please help me.
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 local track = humanoid:LoadAnimation(animation) --load the animation into the humanoid 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!
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) local track = humanoid:LoadAnimation(animation) track:Play() wait(animation_time-span) track:Stop() end)
Remove the wait and stop and it will play continuously