Gun Idle Animation Not Working

Hello, I’m new to animating on Roblox and I’m pretty trash at it. I’ve created this simple hold animation for one of my weapons in my game. When I try it out in my game, yes it does play the animation. But it just ends like right after, how can I get the animation to stay there? This is my simple animation script and a video. However I don’t think the script is the problem.

LocalScript inside Tool

local id = "5610784952"

script.Parent.Equipped:Connect(function()
	game.ReplicatedStorage.Events.GunAnimate:FireServer(id)
end)

script.Parent.Unequipped:Connect(function()
	game.ReplicatedStorage.Events.StopGunAnimate:FireServer(id)
end)

ServerScript in ServerScriptService

local events = game.ReplicatedStorage.Events

events.GunAnimate.OnServerEvent:Connect(function(player, animationId)
	local animation = Instance.new("Animation")
	animation.AnimationId = "http://www.roblox.com/Asset?ID="..animationId
	
	local loadAnimation = game.Workspace[player.Name].Humanoid:LoadAnimation(animation)
	loadAnimation:Play()
	
	events.StopGunAnimate.OnServerEvent:Connect(function()
		animation:Destroy()
	end)
end)

And here’s a video:


Also how would I stop the gun from being sideways? Sorry I’m a noob at this :sweat_smile:

Did you enable “Toggle Looping Animation” in the animation editor? It’s a little button next to the play animation icons. This will ensure your animation plays continually until it is stopped. As for the gun being sideways, you could try some tool grip editor plugins if it is a tool.

You’ll want to make sure that the animation is looped. Import it back into the Animation Editor and set Looped to true (there’s a button in the topbar of the editor, should be a circle with a play button in the middle iirc). You should also set your Animation Priority accordingly (under File I believe)

Hey it works, but when I un equip the tool it wont go back to normal??

Hey thanks this works well, but it wont stop the animation and go back to normal when I unequip the tool?!

Why are you animating the player in a server script? It’d be much more efficient animating it in a local script, something like this:

local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/Asset?ID=5610784952"
	
local loadAnimation = game.Workspace[player.Name].Humanoid:LoadAnimation(animation)
LoadAnimation.Looped = true

script.Parent.Equipped:Connect(function()
	loadAnimation:Play()
end)

script.Parent.Unequipped:Connect(function()
	loadAnimation:Stop()
end)
2 Likes

Call :Stop() on the animation before destroying it. Also, as @amadeupworld2 said, definitely animate it from a localscript. Your animations will replicate to other clients.

Yeah but the rest of the server wont be able to see the animation on that player right?

Stop is not a valid member of animation? image

you need to call :Stop() on loadAnimation, not Animation. loadAnimation is an AnimationTrack, which :Stop() is a part of. Animation is simply the animation object, which itself is not being played. loadAnimation is the actual AnimationTrack being played.