Playing an animation freezes the character

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?

1 Like

I might want to add that the animation itself doesn’t play either

You don’t need to create an AnimationController or an Animator. Just use the animator inside the humanoid to load an animation.

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)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.