I am trying to make a tool that plays an animation when it is activated
The script that is failing is a local script inside the tool.
I can guarantee that script.Parent.event is being fired client side.
there is also an animation instance inside the tool with the animation id
Here is the script.
script.Parent.Event.OnClientEvent:Connect(function()
local player = game.Players.LocalPlayer
local char = player.Character
local controller = Instance.new("AnimationController")
controller.Parent = char.Humanoid
local animator = Instance.new("Animator")
animator.Parent = controller
local animation = script.Parent.Animation
local track = animator:LoadAnimation(animation)
track:Play()
wait(1)
track:Stop()
end)
when the animation is played, the character stops playing any animations at all, including walking but it still moves. Does anyone know why this may be happening?
script.Parent.Event.OnClientEvent:Connect(function()
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait() -- sometimes player.Character doesn't work so you need to use "or player.CharacterAdded:Wait()" to fix that
local Humanoid = char:WaitForChild("Humanoid") -- add a humanoid, so you can play your animation
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://".. YourID -- change YourID to your asset's id
local track = Humanoid:LoadAnimation(animation)
track:Play()
wait(1)
track:Stop()
end)
edit: also, if you want to do something when your tool is activated, make a localscript in your tool with this:
script.Parent.Activated:Connect(function()
-- Do something
end)