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

my hold animation wont continue playing How do i fix this?

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 loadedAnim
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")
		loadedAnim = Animator:LoadAnimation(holdAnim)
		loadedAnim.Looped = true
		loadedAnim.Priority = Enum.AnimationPriority.Action
		loadedAnim:Play()
	end
end)
tool.Unequipped:Connect(function()
	loadedAnim:Stop()
end)

This is a serverScript If nobody can fix this I will have to resort to CFraming, which I REALLY do not want to do. https://www.roblox.com/library/7467408348/betterHold-hoepfully --This is the one im using, Its Incredibly long and looped Original one -- https://www.roblox.com/library/7466688023/hold -- Incredibly short , not looped (well I dont thhtink it is)

---What happens, https://gyazo.com/0acbc706d69860326341bb4a226beea8 when you ReEquipd it plays but then stops after a bit (assuming you are Idle)

1 answer

I fixed it, I had to load and play the animation on the Server AND client so it could replicate, How I did it: I used a RemoteFunction once it is equipped it calls the function and sends the Animation to the server the server then makes an Animator and takes the Passed Animation and loads and playss it there, then it returns the animator which the Client uses to play the animations

--LocalScript
local plr = game.Players.LocalPlayer
local gunMod = script.Parent.Parent["gun model excluding the handle.......obviously"]
local tool = script.Parent.Parent
local loadedAnim
local holdAnim = script.Parent.Hold
tool.Equipped:Connect(function()
	local humanoid = script.Parent.Parent.Parent:WaitForChild("Humanoid")
	if humanoid then
		local animater = script.Parent.RemoteFunction:InvokeServer(holdAnim)
		loadedAnim = animater:LoadAnimation(holdAnim)
		loadedAnim.Looped = true
		loadedAnim.Priority = Enum.AnimationPriority.Action
		loadedAnim:Play()
	end
end)
tool.Unequipped:Connect(function()
	loadedAnim:Stop()
end)
--ServerScript
script.Parent.RemoteFunction.OnServerInvoke = function(plr,holdanm)
	local Animater = Instance.new("Animator")
	Animater.Parent = plr.Character:WaitForChild("Humanoid")
	local l = Animater:LoadAnimation(holdanm)
	l.Looped = true
	l.Priority = Enum.AnimationPriority.Action
	l:Play()
	return Animater
end

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