Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Animation wont keep playing on Equip how fix ?

local plr = game.Players.LocalPlayer
local event = script.Parent.RemoteEvent
local gunMod = script.Parent.Parent["gun model excluding the handle.......obviously"]
local tool = script.Parent.Parent

local holdAnim = script.Parent.Hold
tool.Equipped:Connect(function()
	local animator 
	wait(0.2)
	local humanoid = script.Parent.Parent.Parent:WaitForChild("Humanoid")
	print(humanoid)
	print(humanoid.Parent)
	if humanoid ~= nil then
		animator = Instance.new("Animator",humanoid)
		animator.Parent = humanoid
	end
	holdAnim.Parent = humanoid
	local Animater = humanoid:WaitForChild("Animator")
	local loadedAnim = Animater:LoadAnimation(holdAnim)
	loadedAnim:Play()

	print("H")
end)

This is on a Server Script . What happens: https://gyazo.com/178fd7dc5d1027c5bcb309228055e64e Please help me bustaronies ! There are NO errors in output

Also I just want to thank this Site because I probably wouldnt be coding if it didnt push me to start, thanks to everybody who responed to all my threads, I greatly appreciate you. Anybody can learn LUA

1 answer

Problem

I'm pretty sure all you need to do is loop the animation and set the animation priority to Action(Max priority). Setting it to the Action priority will override all animations that have an animation priority below the Action priority.

You don't need to create the Animator, it's already there, but you can't see it.

Recommendations

  1. You should avoid using wait(n) Waiting for events to be fired is a better solution than wait(n) for example, RunService.Heartbeat:Wait() is better. Using wait(n) or wait() can decrease the performance of your game. If you want more information on avoiding waits, you can look here.

  2. It's a bad practice to create a new Instance and instantly parent it. You should change all the property first, then the last thing you do is parent it. Doing this can increase performance.

Fixed code

local plr = game.Players.LocalPlayer
local event = script.Parent.RemoteEvent
local gunMod = script.Parent.Parent["gun model excluding the handle.......obviously"]
local tool = script.Parent.Parent

local holdAnim = script.Parent.Hold
tool.Equipped:Connect(function()
    local humanoid = script.Parent.Parent.Parent:WaitForChild("Humanoid")
    if humanoid then
       local Animator = humanoid:WaitForChild("Animator")
       local loadedAnim = Animator:LoadAnimation(holdAnim)
       loadedAnim.Looped = true
       loadedAnim.Priority = Enum.AnimationPriority.Action
       loadedAnim:Play()
   end
end)

Hopefully, this should work because I wrote the code here and not in Roblox Studio.

5 comments

0

Ok Ill try it out

0

It did not work, by the animation is incredibly long and Looped when I made it

0

@ym5a Are there any errors in the output?

0

https://gyazo.com/3066095fdc2020e0ffa4a7f7cddb0741 This is what happens, I also added when it is unequipped it stops playing the Animation

0

@MarkedTomate No.

This discussion is preserved as it was. New answers, comments, and votes are closed.