For my system, enemies are just tables that hold info, no models or animations at all. Example table would be like
{
["HP"] = 100;
["CFrame"] = CFrame.new()
}
Then I use a Heartbeat to move them, using CFrame:ToWorldSpace() to move them in the direction they’re facing no matter the rotation, and having them face the next node. You should have nodes on the map which enemies use for movement.
Then about every 10-20 heartbeats, send a Remote to the client which contains the info for the enemies. You can then create the enemies model and tween/animate them nicely on the client, giving you a performant system that can still handle high numbers. My current enemy system can handle about 500 enemies before seeing any impact to performance.
Wouldn’t passing info by using a RemoteEvent be a lot more exploitable? (They can easily change values)
I would recommend using a module to handle enemies and using metatables.
you could have a function like module:SendData() to send the data from the module to the client, lemme write a quick example
local module = {}
local meta = {__index = module}
function module.newEnemy(data)
--[[the table would look like this
{
['HP'] = 100
['CFrame'] = CFrame.new()
['Name'] = "Quick Zombie"
}
]]
local self = {}
self.hp = data['HP']
self.cframe = data['CFrame']
self.name = data['Name']
self.npc = game.ReplicatedStorage.enemies:WaitForChild(self.name)
return setmetatable(self, meta) -- the reason we return the setmetatable is because now in the localscript you can access self through a variable!
end
-- other module functions here lolol
function module:returnData()
return self -- returning this {['hp'] = 100, ['cframe'] = CFrame.new(), ['name'] = 'Quick Zombie', ['npc'] = workspace['Quick Zombie']}
end
return module
I hope this help with making your code a bit more secure!
(This is not required, if you have RemoteEvent checks, then you’re good to go , just suggesting another method I sometimes use.)
We would be sending the remotes TO the client from the server, not TO the server from the client. No remotes are used for interacting with enemies from the client to the server, so its not exploitable. Exploiters can only affect their client and remotes which send to the server.
If you do it like you are, it will cause lag. What you are supposed to do is for example tween them for 0.2 seconds and then once that is done tween it again, you wanna get the next position that it has to go to with the 0.2 seconds tween by lerping the distance. This is how i would do it, don’t know how Kdude did it but if you see this Kdude i would like better explanation as i always like to see different solutions.