How to handle enemy positions

Hello, I am working on a Mulitplayer Tower Defense style game and currently I have my enemy positions handled on the server (Tweening them from one point to another) And when handling a lot of enemies (100) it starts to lag. I need to know the exact location of my enemy for my tower attack checks to work, so I can’t just play all tweens on the client because then the enemy positions won’t replicate to the server.

Alternatively

Since this isn’t exactly something that has to be super accurate would playing all of my tweens on the client and just firing a remote event for the server to damage that npc be a good option?
(im not sure how this would work if a player is experiencing ping)

This is my first project where I have to take in account a lot of server-client communication so im sorry if something makes no sense or is just a bad idea :sweat_smile:

1 Like

Also theres a lot of posts on making an entity system, you could have the server do lerp and do a simple alpha equation and send the info to the client and update the cframe.

What I would do is store all enemies on the server with the information you need. For this example lets just do position only. I would send a remote event as often as you can, maybe using a heartbeat, though how you do that is up to you. Something like this possibly?

--> Server Side

local Enemies: {{cf: CFrame}} = {} --> Table of enemies
local UpdateRemote: RemoteEvent = --> RemoteEvent Location

--> Loop here
UpdateRemote:FireAllClients(Enemies)
--> Client Side

local UpdateRemote: RemoteEvent = --> RemoteEvent Location

UpdateRemote.OnClientEvent:Connect(function(enemies)
   --> Loop through enemies and tween them to the their new positions
   for _, enemyInfo in enemies do
      local NewCFrame: CFrame = enemyInfo.cf
      --> Get Model and Tween to new CFrame
   end
end)