Storing Loaded Animation to ObjectValue in Server does not Replicate to Client

  1. What do you want to achieve?
    I want to be able to store loaded animations on the server so I can play the animation anywhere I like.

The function LoadAnimations takes in a folder of animations that will be copied and replaced AnimationObject with ObjectValue with the value being the AnimationTrack loaded from the character. This is the folder I am passing in:


This is the expected result after the function is complete:

  1. What is the issue?
    As of now, the code I provided below only replicates to the server and not to the client. I thought whatever is replicated on the server is done for the client as well.

  2. What solutions have you tried so far?
    The solution I have at the moment is to replicate the loading process on the client side and store the loaded animation to the created ObjectValue made by the server.

function module:LoadAnimations(AnimationFolder: Folder, Character: Model)
	if Character.Parent == nil then
		repeat task.wait() until Character.Parent == workspace
	end
	
	local Humanoid: Humanoid = Character:WaitForChild("Humanoid")
	local Animator: Animator = Humanoid:WaitForChild("Animator")
	local AnimationTracks = {}
	
	local newFolder = Instance.new("Folder")
	newFolder.Name = AnimationFolder.Name
	
	if AnimationFolder.Name == "Animation" then -- Folder made to store ObjectValue
		newFolder.Name = "LoadedAnimations"
		newFolder.Parent = Character
	end
	
	for _, Animation in pairs(AnimationFolder:GetChildren()) do
		if Animation:IsA("Folder") then
			module:LoadAnimations(Animation, Character).Parent = newFolder
		elseif Animation:IsA("Animation") then
			local LoadedAnimation = Animator:LoadAnimation(Animation)
			
			local ObjectValue = Instance.new("ObjectValue")
			ObjectValue.Parent = newFolder
			ObjectValue.Name = Animation.Name
			ObjectValue.Value = LoadedAnimation
		end
	end

	return newFolder
end

On Client:


On Server:

1 Like

Use RemoteEvents:

1 Like

I mentioned that is one of the solutions, but I am asking right now to see if there’s a better solution to this problem

I don’t think so. You need to connect between the server and the client; you need a remote event.

What confuses me is that this function is made on the server which should replicate to the client, but the client couldn’t see what is replicated for some reason

Wait, nvm, I have 1 more soulotion.

You are trying to store animation on the server and run it on the client.
Not client-to-server, right?

So what do you using to do that?

I recommend that you use a bool value or an int value instead.

Bool value to store true or false
Int value to store numbers: any number from -9999 to 9999
So you can store 1 and check with the client; if it’s 1, then do what you want.

I added two images below the post showing the AnimationTrack stored inside the ObjectValue. As you notice, the server can see the value being stored, but the client does not have that added. As mentioned before, I used a RemoteEvent as you stated to store the loaded animation locally.

Can you show me the server part, where it stores, and the client part?

I don’t see how storing a bool or int value would help in this case. The problem here is the value being stored is not replicated to the client. I am still confuse one why it would not be replicated.

This is my explorer:

bro I faced this problem before. I know the fix, but I don’t know what is wrong with your scripting. Just send me the server script and client.

This is the server

function module:LoadAnimations(AnimationFolder: Folder, Character: Model)
	if Character.Parent == nil then
		repeat task.wait() until Character.Parent == workspace
	end
	
	local Humanoid: Humanoid = Character:WaitForChild("Humanoid")
	local Animator: Animator = Humanoid:WaitForChild("Animator")
	
	local newFolder = Instance.new("Folder")
	newFolder.Name = AnimationFolder.Name
	
	if AnimationFolder.Name == "Animation" then
		newFolder.Name = "LoadedAnimations"
		newFolder.Parent = Character
	end
	
	for _, Animation in pairs(AnimationFolder:GetChildren()) do
		if Animation:IsA("Folder") then
			module:LoadAnimations(Animation, Character).Parent = newFolder
		elseif Animation:IsA("Animation") then
			local LoadedAnimation = Animator:LoadAnimation(Animation)
			
			local ObjectValue = Instance.new("ObjectValue")
			ObjectValue.Parent = newFolder
			ObjectValue.Name = Animation.Name
			ObjectValue.Value = LoadedAnimation
			ReplicatedStorage.RemoteEvents.LoadClientAnimation:FireAllClients(ObjectValue, LoadedAnimation)
		end
	end

	return newFolder
end

This is client:

RemoteEvents.LoadClientAnimation.OnClientEvent:Connect(function(ObjectValue: ObjectValue, LoadedAnimation: AnimationTrack)
	ObjectValue.Value = LoadedAnimation
end)

On second thought, when I tried to pass the ObjectValue and AnimationTrack through, it resulted nil on the client. I’m currently investigating to see how to fix it, but essentially that’s the current solution I have in mind.

I really didn’t understand anything from your scripting, but I will show you what I can do to make this work.

Here is a video:


So the video above shows how you can store or transfer from server to local, but instead of my print statements, you can replace them with your code.

Also, sorry for the late answer. I was making the video and editing it.

1 Like

I appreciate the efforts you went through to help me, thanks for that! I noticed you’re still confused which I will explain here and update this information in my post. This is what the code does.

The function LoadAnimations takes in a folder of animations that will be copied and replaced AnimationObject with ObjectValue with the value being the AnimationTrack loaded from the character. This is the folder I am passing in:


This is the expected result after the function is complete:

Has anyone been able to find out why the AnimationTrack is not being replicated to the client?