After hours of scouring the Devforum, I have not found a single solution to the problem I am facing. My customized “Animate” local script is not replicating for other clients on the server. Obviously this is an issue, because from the POV of other players, you are just gliding around.
What solutions have you tried?
All separate attempts
- Creating an Animator instance in the humanoid upon CharacterAdded
- Using remotes to communicate between the server & client, when the Animator instance has been replicated on the server, and passing that to the
InitAnimations
function. - Using remotes to communicate to the server when an animation needs a change.
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TextChatService = game:GetService("TextChatService")
local Assets = require(ReplicatedStorage.Databases.Assets)
local animationsVar = script.Animations
local player = Players.LocalPlayer
local RemoteHandler = require(player.PlayerScripts.CoreClient.RemoteHandler)
local char = player.Character
local root = char:WaitForChild("HumanoidRootPart")
local hum = char:WaitForChild("Humanoid")
local animWeight, targetWeight = {}, {}
local charDancing = false
local initialized
local function SetWeight(anim, weight)
if not anim or not weight then
return
end
targetWeight[anim] = weight
end
local function InitAnimations()
if initialized then
return
end
initialized = true
local anims = {
WalkForward = hum:LoadAnimation(animationsVar.WalkForward),
WalkRight = hum:LoadAnimation(animationsVar.WalkRight),
WalkLeft = hum:LoadAnimation(animationsVar.WalkLeft),
WalkBack = hum:LoadAnimation(animationsVar.WalkBack),
Run = hum:LoadAnimation(animationsVar.Run),
Idle = hum:LoadAnimation(animationsVar.Idle),
RatDance = hum:LoadAnimation(animationsVar.RatDance)
}
for i, v in pairs(anims) do
v.Priority = Enum.AnimationPriority.Core
v:Play(0, 0.01, 0)
v:AdjustWeight(0)
do
animWeight[v] = 0
targetWeight[v] = 0
end
end
RunService.RenderStepped:Connect(function()
local dir = root.CFrame:VectorToObjectSpace(root.AssemblyLinearVelocity)
local moveSpeed = dir.Magnitude
local isRunning = hum.WalkSpeed >= 20
if charDancing and moveSpeed > 0.5 then
charDancing = false
anims.RatDance:Stop()
end
for i, v in pairs(anims) do
SetWeight(v, 0)
end
do
if moveSpeed < 0.5 then
SetWeight(anims.Idle, 1)
anims.Idle:AdjustSpeed(1)
elseif isRunning and dir.Z < -1 then
SetWeight(anims.Run, 1)
anims.Run:AdjustSpeed(1.5)
else
if dir.Z < -1 then
SetWeight(anims.WalkForward, 1)
anims.WalkForward:AdjustSpeed(1)
elseif dir.Z > 1 then
SetWeight(anims.WalkBack, 1)
anims.WalkBack:AdjustSpeed(1)
end
if dir.X > 1 then
SetWeight(anims.WalkRight, 1)
anims.WalkRight:AdjustSpeed(1)
elseif dir.X < -1 then
SetWeight(anims.WalkLeft, 1)
anims.WalkLeft:AdjustSpeed(1)
end
end
end
for i, v in pairs(targetWeight) do
local current = animWeight[i] or 0
local newWeight = current + (v - current) * 0.2
i:AdjustWeight(newWeight)
animWeight[i] = newWeight
end
end)
TextChatService.SendingMessage:Connect(function(msg)
if string.lower(msg.Text) == "lemme show you how we really do it" and not charDancing then
anims.RatDance:Play(0, 0.01, 0)
charDancing = true
end
end)
end
InitAnimations()
Folder Setup:
Any help towards getting this in a working state would be greatly appreciated.