That only happens if the animation is run on that player’s character. But in my case, they are NPCs
Then you can use a module script to control all of them through one local script placed in StarterPlayerScripts. That’s what I do too.
If the NPCs are controlled by the server I’m assuming that means the networkownership()
is already owned by the server. Why wouldn’t the speed be controlled by the server?
The process of “controlling” them is gonna be quite complicated though, because the walking/running/jump/idle animations are handles by the Default “Animate” script by roblox which is VERY long, and they are full of “AdjustSpeed”, “AdjustWeight”, “Stop”, “LoadAnimation”, and basically a ton of other animation actions. Do I just use remote events to fire for every singel of those actions every time?
The speed IS controlled by the server. The walk speed is controlled by the server, the walk animation speed is also controlled by the server. But because it is controlled by the server, the animation speed wasn’t replicated to the client and so on the client, the animation is played slower and it stutters every second because of the difference in animation speed.
^^ take a read from this. Might have something useful for you
You don’t have to fire any remote though. If every player has their own local script they will already see the changes correctly on their client (it’s actually better since the animations would correctly sync with the walkspeed/velocity they see). I was suggesting using a local script not only cause of the replication issues but also to improve performance on the server.
NPCs are supposed to be animated on the server.
If an Animator is a descendant of a Humanoid or AnimationController in a Player’s Character then animations started on that Player’s client will be replicated to the server and other clients.
If the Animator is not a descendant of a player character, its animations must be loaded and started on the server to replicate.
but the thing is right now the client isn’t seeing any changes…
The server used AdjustSpeed() on the animation track, but the client doesn’t see the change.
I’m talking about changes like the NPC’s walkspeed. AdjustSpeed will be perfectly synced with what the client is seeing if you use a local script.
That’s the issue. “AdjustSpeed()” does not replicated from server to client. “AdjustSpeed()” is currently called on the server because it’s an NPC. When I use a local script, the local script will not run because the local script will be parented under workspace.
Yes, that is how it is currently in my game. But AdjustSpeed() is not replicated to the client, so from the client the animation looks very goofy. How can I properly replicate the animation track to the client?
Could you send a reproduction file so we can investigate further?
I haven’t tested myself but assuming this is true…
1. Try sending the new speed value and the animation track to the client.
-- SERVER SIDE
local walkAnim = NPC.Humanoid.Animator:LoadAnimation(WalkAnimation)
walkAnim:Play()
RemoteEvent:FireAllClient(walkAnim, 2) -- set the walk anim speed to 2
-- CLIENT SIDE
RemoteEvent.OnClientEvent:Connect(function(anim: AnimationTrack, speed: number)
anim:AdjustSpeed(speed)
end)
2. Play the animation locally instead. The NPC’s Humanoid state changes are replicated to the client. You should be able to get away with making a local script of the NPC’s animator and letting it run like normal (assuming there’s no serverside dependency).
Basically just set the server animation control script to the client’s using roblox’s new RunContext system.
I’m pretty sure you’d need to create a manual animation controller on each client, or you’d need to implement some sort of way to detect the npc’s animations playing.
Yes, I’ve tried this. But when animation track is sent to the client, the client can’t read it (it’s nil)
Local scripts don’t run in workspace. Does changing “Run Context” make it run on the client?
Yes, that’s what the new roblox feature does. Your local script will run on the client even if it’s in workspace if it’s set to that run context.
Ah I see, thanks for the clarification. What about other custom animations played on the server? Do I just remote event and make my own script on the client?
Just convert your server script to the client script by switching it’s RunContext. If it needs to talk to other server scripts, you could build an interface using remote events.