What do I want to achieve?
I want enemies in my game to correctly follow players without causing desync issues
What is the issue?
Currently, enemies follow the player on the client side,
Once the enemies are defeated, everything goes back to normal.
Here’s a video showing the issue:
robloxapp-20250217-1023300.wmv (2.0 MB)
What solutions have I tried?
I tried making the server handle enemy movement calculations, but the issue persisted.
I used RunService to handle movement updates, but the problem remained.
I tried reducing the update frequency of enemy movement, but it didn’t feel smooth.
Additional details
Bullets are also handled on the client and then replicated to other clients.
Player movement is based on a Roblox platformer template, which might… be affecting synchronization.
This is the code I’m currently using for enemy movement:
local function Start(self)
local alpha = 0.1
local secondAlpha = 0.01
while self.Active do
local target = Global.GetNearestPlayer(self.Root, 70)
if target then
local targetPos = target.HumanoidRootPart.Position
local offset = CFrame.Angles(0, math.rad(90), 0)
local pivotOffset = CFrame.new(self.Cannon.Size.X/2, 0, 0)
local finalCFrame = CFrame.lookAt(self.Root.Position, targetPos) * offset * pivotOffset
self.Direction = (targetPos - self.Root.Position).Unit
self.Cannon.CFrame = self.Cannon.CFrame:Lerp(finalCFrame, alpha)
self.Target = true
else
local finalCFrame = CFrame.lookAt(self.Root.Position, self.Root.Position + self.Direction)
self.Cannon.CFrame = self.Cannon.CFrame:Lerp(finalCFrame, secondAlpha)
self.Target = false
end
task.wait()
end
end
Could the bullets be affecting enemy synchronization?
Is there a better way?