well i am confused on how to handle multiple stuff at the same time lets take this as an example
4 players in a game that each player has like 30 troops with each troop has unique abilityl+ a cooldown for that ability and these players fight a boss that has unique abillity in different phases
how can a dev handle this like all of these things happen at the same time?
What do you mean by how can a dev handle all of this ?
How can a dev make/script it ?
Generally, you would have multiple different scripts which would handle these different things. For example, you might have a script which handles the spawning of troops, and you might have a different script which handles the behavior of troops themselves. It doesnβt have to be one big script - you can separate things by abstracting them into ModuleScript
s, for example, which could contain information about how a certain troop behaves. Making sense of these concepts and knowing how to write them out in code should help you develop your game.
use task.spawn
it makes a new thread where you can yield with out yielding the whole scripts it is like a script running inside a script so even if an error happened in the new thread it will not effect any other threads
This is a big question and will take some research.
Event-Driven System
Robloxβs RunService
Data Organization
Concurrency with task.spawn
Cooldown Management
Phase Management for Boss
Efficient Iteration
Modular Design
You should give material for further reading and perhaps give a brief overview of these concepts so that the OP doesnβt get confused.
well i dont want any script or anything i just want to get an idea on how they do this like multiple scripts wont solve this problem since it will cause so mich lag
u ve read my mind lol but i think i know some of them
well i ve made some searches about it and found that the only reason that they are considered useful is because when u yield using wait() it lets the other part of the script run so i dont think thats the correct one
No? What? What is the basis for this? Large quantities of script donβt cause lag. Unoptimized code does.
yeah but how to actual impelemnt it without causeimg so much lag
oh sorry i didnt read it fully i thougjt for some reasons u said every troop has its own scriptπ₯Έ
Itβs too huge of a subject to post here. But youβre right β¦ Here is good start.
Task Functions (wait(), spawn(), delay()) - Roblox Advanced Scripting #4
How to Activate Multiple Objects at Once | Roblox Studio
Coroutines - Roblox Advanced Scripting #8
i think oop and events could make that easier
local fireTroop = troop.new()
fiireTroop:AddAbility("FIRE EXPLOSION", function()
--ability code
end)
fireTroop.abilityFired:Connect(function(abilityName)
--code
end)
fireTroop:FireAbility("FIRE EXPLOSION")
it seems that u guys dont understand on what im struggiling on
well spawn and couroutimes functions run only when the main thread yields and if there are so many task.spawns then it would make a lot threads that would cause lags and each thread will only one if the previous ones either yield or stop
you can reuse threads however that can be hard
but the abilitys donot have to happen at the same time and you donβt have to create new threads for them they can just work one after another
troop1 fires ability
troop2 fires ability
troop3 fires ability
etcβ¦
and the time difference between each one will be a small number that you will not even feel that the abilityβs are running 1 after another (depends on the code efficiency)
if the threads are closed then it wouldnβt harm performance much
the first thing that comes to mind to solve this is ModuleScripts and OOP
everyone else answered that already though
but from what I understand, you are also overwhelmed on how to even manage all these
say you have a game that has this:
every player has an ability (Throw rocks, slap etc. being really random here)
players fight unique bosses
players earn money when kill a boss based on their contribution of damage
the game structure could look like this:
-
Core Systems
- playerClass
β’ handles player stats, abilities, inventory
β’ manages state of player like dead or alive - abilitySystem
β’ defines base ability behavior
β’ handles cooldowns, animations
β’ manages ability effects
β’ each ability is its own moduleScript (throwRocks, slap, etc) - combatSystem
β’ damage calculations are done here
β’ manages combat states - moneySystem
β’ tracks player earnings
β’ manages rewards
- playerClass
-
Boss System
- bossManager
β’ spawns and manages boss instances
β’ tracks active bosses - bossClass
β’ individual boss behaviors
β’ boss-specific abilities
β’ health/damage tracking
β’ separate modules for each boss (iceBoss.new(), fireBoss.new()) - damageTracker
β’ records player damage contributions
β’ calculates reward shares
β’ manages combat logging
- bossManager
-
Client-Side
- uiManager
β’ displays health bars
β’ shows damage numbers
β’ updates currency display - abilityController
β’ handles player input
β’ shows ability cooldowns
β’ manages ability animations - effectsHandler
β’ visual effects for abilities
β’ combat impact effects
β’ boss special effects
- uiManager
-
Network
- remoteEvents
β’ abilityActivated
β’ damageDealt
β’ bossDefeated
β’ rewardEarned - remoteFunctions
β’ getPlayerStats
β’ requestAbilityUse
β’ fetchBossInfo
- remoteEvents
heres some examples:
player joins:
- server creates new player instance: playerClass.new()
- sets up all player systems and trackers
Player Uses Ability:
- client detects input
- abilityController validates cooldown
- server validates and processes ability
- server signals all clients for effects
Boss Takes Damage:
- server calculates damage
- damageTracker records contribution
- UI updates for all players through events
Boss Dies:
- server calculates rewards
- moneySystem handles earnings of players
- players receive notifications through events
i hope this clears some things up, this allows your game to run many things all at once with organization
This is not really the case. There are 100βs of script going in the background. Focus on one troop for each unique ability, script it generically. There is nothing wrong with each troop have itβs own scriptβ¦ In fact this for me this would be the way to go, along with over all scripts for them.
βLarge quantities of script donβt cause lag. Unoptimized code does.β - Bilon BilonGamer 2025
thanks so much and this looks so clean but there some little bit details u ve missed
- i said every player has like 30 troops (which some games have this system) and there are like 4 or 5 player against a boss
- i havent mentioned this , the damage dealers are these troops with their unique abilties
- this is the most important one how to make the server run the boss fight phases with its movements ,abilties β¦ect while handleing the cooldown of each troop ability and handeling each troop attacking simultaneously and manageing all that without causing an issue in perfomace . now i dont want a script or anything i just want ideas since my theory is fhat the asynchrous tasks arent enough
So what you mean is an RTS game with boss fights, thats pretty interesting
Iβm currently developing an RTS myself and what we have going on is; We have 2 base class module for units, one for client; one for server
(Credits to nfroizey for scripting the framework)
Youβd have a module for each unit
itβd look like like:
Client:
BaseUnit:new()
BaseUnit:ShowHit()
UnitHitEvent.OnClientEvent:Connect(BaseClass.ShowHit)
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Server:
BaseUnit:new()
BaseUnit:Hit(boss)
(VFX and animations are handled on the client to reduce server lag using ShowHit)
Then using an open source module called classic, we do BaseClass:extend ; (classic allows you to create new classes that are extensions of classes, so you can use the same methods) For each unit class we have a server module and a client module.
Ex: youβd have Soldier module in both server and client, itβd use the same things as the base class except itβd have a gun, you would be able to code that in the module.
"
Client:
Soldier = ClientBaseClass:extend
Soldier:new()
Soldier:ShowHit()
(Now you can code the gun shooting here pretty comfortably)
Now you can do
UnitHitEvent.OnClientEvent:Connect(Soldier.ShowHit)
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Server:
Soldier = ServerBaseClass:extend
(you donβt have to do anything here as you can just use the baseclass methods)
You can do:
Soldier:Hit(Iceboss)
You mentioned you had unique abilities
For the abilities, you could create modules handling each ability on server and client and on the modules i just mentioned
say you have an ability called Grenade ability, itβd throw the grenade at the enemy and itβd explode after a few seconds
you could make it so that
ββ
Server in Soldier module:
GrenadeAbility:MakeUnitUse(Unit)
And on Grenade (client version), youβd set up connection for it to show the effects and animations
(The approach for abilities might not be the best way to go)
TLDR; Troops and abilities should have client side modules and server side modules to handle commands and effects, effects should be handled in client.
(sorry for any non-sense)