Odd Issues With Animation Loading/Replication

Hi, everyone. First post here - and I’ve got a problem I’ve been headbutting for the past few hours.

I’m attempting to load animations onto my character’s humanoid, and I’m getting a consistent result; the animations aren’t playing. At first I assumed that the problem occurred because I was creating the Animation objects themselves client-side, but after re-initializing the localscript either by changing classes or resetting I received an error:

This error persists if I choose to instead create the objects from a serverscript and call LoadAnimation on them from the client. Stranger still, I played around with disabling scripts or commenting out chunks of code to dig to the root of the problem, and if I refrain from cloning certain scripts to the character’s class folder (which contains the core scripts) the issue desists. If I add a nominal wait time to the beginning of the class localscript before I call LoadAnimation (anywhere from 0.5 to 1s), the issue desists. The only commonality between the cloned scripts and the class script is that they both reference the player’s character and humanoid (CritBehavior, HPBehavior, StateBehavior).

image

Moreover, even when I perform the above workarounds necessary to cause my animations to load and play correctly, they do not replicate to the server when I utilize the Test Server mode in studio. I’ve read everywhere that this behavior is not intended and that animations can be played client-side whilst still replicating to other players.

I’ve done some digging into the topic and many similar threads suggested that the character and humanoid can exist without actually being part of the datamodel, and I tried the code they provided that they claimed fixed this particular error, to no avail. I’ve also tried waiting for the Animator object after first calling LoadAnimation, and the script proceeds as if one was created, despite the explorer showing I clearly have an empty humanoid.

If anyone’s encountering a similar issue or knows a fix, I’d appreciate your help. Thanks!

1 Like

If a arbitrary wait fixes your problem, this is likely due to the character not being created fast enough. It seems like a really weird edge case. Maybe try using .CharacterAppearanceLoaded and wait for that event before loading the animation.

2 Likes

can you include the code for the local script.

2 Likes

Sure - the entire thing is 1K+ lines, so I’ll just post the relevant snippets up to the point where I load the animations.

function wfc(p, o, t)
	return p:WaitForChild(o, t)
end

--
i_n = Instance.new
v3 = Vector3.new
ud2 = UDim2.new
c3 = Color3.new
bcn = BrickColor.new
cfn = CFrame.new
cfa = CFrame.Angles
ray = Ray.new

rand = math.random
ceil = math.ceil
floor = math.floor
sqr = math.sqrt
abs = math.abs

uit = Enum.UserInputType
kc = Enum.KeyCode

plr = game.Players.LocalPlayer
char = plr.Character or plr.CharacterAdded:wait()
rig = nil

cam = workspace.CurrentCamera
mouse = plr:GetMouse()

hume = wfc(char, "Humanoid")
hrp = wfc(char, "HumanoidRootPart")

anims = {}
paused = {}

--
function newAnim(id, n)
	local new = i_n("Animation", char)
	new.Name = n or "CoreAnim"
	
	new.AnimationId = "rbxassetid://"..id
	new = hume:LoadAnimation(new)
	
	return new
end

-- ANIMATION
idle = newAnim(3244974507, "Idle")
walk = newAnim(3245159860, "Walk")
jump = newAnim(3245188365, "Jump")
fall = newAnim(3245191409, "Fall")

slashA = newAnim(3245199497, "slashA")
slashB = newAnim(3245200447, "slashB")
slashC = newAnim(3245201437, "slashC")

Update on this - I attempted to wait for and print the ‘Animator’ object as a fix, and the result is strange, if not silly.

function newAnim(id, n)
	local new = i_n("Animation", char)
	new.Name = n or "CoreAnim"
	
	new.AnimationId = "rbxassetid://"..id
	new = hume:LoadAnimation(new)
	anims[#anims+1] = new
	
	if not rig then rig = wfc(hume, "Animator")
		print(rig)
	end
	
	return new
end

-- ANIMATION
idle = newAnim(3244974507, "Idle")
walk = newAnim(3245159860, "Walk")
jump = newAnim(3245188365, "Jump")
fall = newAnim(3245191409, "Fall")

slashA = newAnim(3245199497, "slashA")
slashB = newAnim(3245200447, "slashB")
slashC = newAnim(3245201437, "slashC")

The output returned that the Animator was in fact created, and yet when I searched the Explorer for it, I had a completely empty Humanoid…

Is this a common occurrence? I really don’t feel like it is.

Just a thought.
Would you please look into the HumanoidRootPart to see if there is what you are looking for.
I ask as I seem to recall seeing responses before where some items appeared there instead of in Humanoid.

image

Nothing here, boss. Wonder why it says it exists in the Humanoid if I clearly don’t see it…

I should mention that even if I add an arbitrary wait time to prevent the loading issue, the animations still don’t replicate to other players when I use the Test Server mode in Studio. This is consistent across all variations of loading, even if I use pre-made animation objects.

Well, I dug - and I’m an idiot.
This function was being called from StateBehavior as soon as the character loads (it removes status effects when you switch classes).

function handler:ClearState(n)
	for k,v in pairs(states) do
		if k == n or not n then v:Destroy() end
	end
	
	for _,v in pairs(hume:GetChildren()) do
		if v.Name == n or not n then v:Destroy() end
	end
end

It was deleting the animator. Thanks, brain.

1 Like

ive come across this error too before, usually happens to me after the first time a character loads in tho

anyways, to fix it, i do something like this:

while not client.Character or not client.Character:IsDescendantOf(game) do wait() end