Animation Help (Idk why there's so much latency)

Alright, so basically here’s what I’m working on. I’m working on a sword system, and this is honestly the first time I work with roblox animation. It’s pretty annoying seeing as how I think I’m doing everything right; however, every single time I load a new animation, it has this insane latency. I am loading the animations in on the client because as you could imagine, playing animations on the client where the inputs are handled, the animations would play almost instantaneously. That just does not seem to be the case here. It seems to be taking forever. Here’s a gif showing what’s going on.

https://gyazo.com/d2886f182df50052cc594003f6b477b5

Here’s a bit of the code:

Animation Loading Function

function AssignAnim(id,char,name)
	local track
	
	if not char:WaitForChild('Humanoid'):FindFirstChild(name) then
		local new = Instance.new('Animation')
		new.AnimationId = 'rbxassetid://' .. id
		new.Parent = char:WaitForChild('Humanoid')
		new.Name = name
		track = char:WaitForChild('Humanoid'):LoadAnimation(new)
		track:Play()
	else
		track = char:WaitForChild('Humanoid'):LoadAnimation(char:WaitForChild('Humanoid'):FindFirstChild(name))
		track:Play()
	end;
	
	return track
end;

Input Connections

uis.InputBegan:Connect(function(input,chat)
	if not chat and Equipped then
		if input.UserInputType == Enum.UserInputType.MouseButton2 then
			blocking = true
			
			--if curAnim then
				curAnim:Stop()
				curAnim = AssignAnim(animMod.Single_Sword_Anims.Block1,char,'Block')
			--end
		end;
	end;
end)

uis.InputEnded:Connect(function(input,chat)
	if not chat and Equipped then
		if input.UserInputType == Enum.UserInputType.MouseButton2 then
			blocking = false
			
			--if curAnim then
				curAnim:Stop()
				curAnim = AssignAnim(animMod.Single_Sword_Anims.Idle,char,'Idle')
			--end
		end;
	end;
end)

So that’s what I got. Why does it take so long to show the animations to everyone else?

1 Like

maybe you’re putting too much pressure on the server, try seeing if the script repeats code.

1 Like

Let me get this straight. If it doesn’t find the animation in the humanoid, it creates an animation, and loads it into the humanoid, right? But in the else statement, it loads it another time and plays it even though the animation is there?

Why not just play the animation if it already exists instead of loading it into the humanoid again? That MAY solve the latency a bit, but if it doesn’t, it’s probably a connection issue with the server or something like that.

That’s what the else does. If it doesn’t find the animation, it creates one and plays it, if it does find one, it just loads that one.

That’s all being done on the client

So is it already loaded, or it is just there? When you say :LoadAnimation, the animation always is playable until the player respawns, and then you just load it again.

Do you use a remotefunction? Because remotefunctions can delay for server/client, client/server depending on a player’s ping ingame.