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:
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.
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
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
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.
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.
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
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 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: