Converting Server Script Animations to Local Script

I’m trying to covert my weapon animation code to a local script since running animations on the server isn’t the best.

I’ve tried using a remote event and sending a message that the local animation is now idle but It doesn’t feel very practical

how the old script worked was that
If the local animation has finished it would send a message “idle”
the server would check the message and if it matched the server state
it would change the server state to “idle” aswell

whats the best way to convert it to a local script?

tool.Equipped:Connect(function()
	state = "equipping"
	idle = char.Humanoid:LoadAnimation(animations.idle)
	equip = char.Humanoid:LoadAnimation(animations.equip)
	equip:Play()
	equip:GetMarkerReachedSignal("ended"):Connect(function()
		idle:Play()
		state = "idle"
	end)
end)

tool.Unequipped:Connect(function()
	state = "unequipped"
	stopanimations()
	if canswing == true then
		canswing = false
	end
	animationnumber = 1
	if delaytask then
		task.cancel(delaytask)
	end
end)

function swing()
	params.FilterDescendantsInstances = {char}
	local randomswingaudio = math.random(1,#swings)
	local hitchar = {}
	local parts
	if animationnumber == 1 then
		current = char.Humanoid:LoadAnimation(animations.swing1)
	elseif animationnumber == 2 then
		current = char.Humanoid:LoadAnimation(animations.swing2)
	elseif animationnumber == 3 then
		current = char.Humanoid:LoadAnimation(animations.swing3)
	end

	current:Play()
	
	current:GetMarkerReachedSignal("start"):Connect(function()
		canswing = true
		playsound(swings[randomswingaudio],1.5,1)
		while canswing do
			parts = workspace:GetPartBoundsInBox(char.HumanoidRootPart.CFrame * CFrame.new(0,-.5,-4),Vector3.new(5, 4, 6.5), params)
			for i, v in pairs(parts) do
				if v.Parent:FindFirstChildOfClass("Humanoid") and not table.find(hitchar, v.Parent) then
					table.insert(hitchar, v.Parent)
					local randomimpact = math.random(1,#impacts)
					playsound(impacts[randomimpact],1.5,1)
					v.Parent:FindFirstChildOfClass("Humanoid"):TakeDamage(35)
				end
			end
			task.wait()
		end
	end)
	current:GetMarkerReachedSignal("end"):Connect(function()
		canswing = false
	end)
	current:GetMarkerReachedSignal("lol"):Connect(function()
		if animationnumber == 3 then
			animationnumber = 1
			delaytask = task.delay(endlag,function()
				state = "idle"
			end)
		else
			if animationnumber < 3 then
				state = "idle"
				animationnumber += 1
			end
		end
	end)
end

Thanks! shiva.

Hey Shiva. It seems that the only way for this to work out properly would be using a remote event, but in your use case you said it doesn’t feel very practical, so unfortunately I don’t have much of a suggestion. Though, why are you handling animations on the server? That doesn’t seem very practical itself - playing animations on the client is smoother and better performance-wise. This reason may give people a better understanding of why you’d handle this on the server when it can definitely be done on the client, otherwise people would just suggest moving your whole script to one that is handled on the client.