Hello developers!
I’m not pro at scripting and i would like to know how to make optimized tower defense game, so almost any device could take hundreds of entities on the map?
I searched up, people was doing something with sending data at client side and rendering everything there, so they could do very optimised game. As a basic level scripter i just was spawning entities at server side and were moving it with waypoints that isn’t gonna be that optimized, from scripts at other posts i didn’t understand anything! Please help me find out how to optimize my game
Note: currently my game lags at 100-200 entities, if there’s more my game just freezing (that causes bad things, that my towers are shooting rarely, but entities doesn’t loose their speed, so that ruins gameplay beacuse they take less damage, this is unfair to players)
It depends on the player’s device, if player’s device is bad, it will lag more.
And don’t add a script on every entities, if will make game lag more, Instead, just make one script control all of the entities.
local function spawnEntity()
-- lets assume that this function is code that spawns entity on the spawn position
return Entity
end
while wait(2) do
local entity = spawnEntity()
entity.Humanoid:MoveTo(endPosition)
entity.Humanoid.MoveToFinished:Connect(function()
tower:TakeDamage(entity.Humanoid.Health)
end)
end
If you don’t a humanoid don’t use it, instead lerp the enemy. Or if you do need a humanoid disable humanoid states you don’t need and use a path finding module like simple path. It would also help if you provided a script.
Whatever states you don’t need. Since you’re making a tower defense game probably everything besides running, but it’s up to you. But, since you’re only doing moving I’m assuming, I doubt you even need a humanoid.
This is actually pretty feasible. Depends on how you want to accomplish it though.
You would have to make all of the character models (both tower and enemy) on the client for the best performance.
On the server side of things, every entity would be an invisible, tiny point that is moved between positions. The client will clone and position character models to follow this point. You can use attributes on the points to do things like facing direction or stun.
The little points can just be Attachments under Terrain, or very small parts moving through the workspace. I’d recommend doing attachments with attributes.
Animation Controllers are going to be what animates your little enemies (and towers for that matter). They work the same as playing animations on a Humanoid. This is obviously all done on the client, as that is where your character models are cloned.
Next, I’d start by doing something to the humanoid inside the character models. That already eliminates a lot of the issues you’ll face with performance.
While humanoids are good for clothing, they aren’t necessary. You can achieve clothing on non-humanoid rigs by using SurfaceGuis, but it doesn’t look super good and I’m not entirely sure how performant it is.
Your other option is to just disable EvaluateStateMachine on the humanoid and be done with them. This is what I would do personally, as it keeps humanoid clothing but disables every other internal force or calculation done by the humanoid.
Things like movement can be achieved either through TweenService(not recommended), or by Lerping(recommended). Use one of these methods on your tiny points on the server to move them throughout the world.
As for easier things like enemy health or tower stats, these can just also be attributes on your server-sided point.
Sorry about not making this post a solution yet… I dont know what i was thinking about back then, but this actually worked pretty well! About bridge thingy i just can make more waypoints, anyway thanks for helping. Humanoids actually arent best at this thing, and also thing about replicating models to every client too not very good.