How to handle multiple things happening

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?

9 Likes

What do you mean by how can a dev handle all of this ?

How can a dev make/script it ?

4 Likes

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 ModuleScripts, 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.

6 Likes

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

4 Likes

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

3 Likes

You should give material for further reading and perhaps give a brief overview of these concepts so that the OP doesn’t get confused.

2 Likes

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

2 Likes

u ve read my mind lol but i think i know some of them

3 Likes

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

3 Likes

No? What? What is the basis for this? Large quantities of script don’t cause lag. Unoptimized code does.

2 Likes

yeah but how to actual impelemnt it without causeimg so much lag

3 Likes

oh sorry i didnt read it fully i thougjt for some reasons u said every troop has its own scriptπŸ₯Έ

3 Likes

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

3 Likes

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")
3 Likes

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

2 Likes

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

3 Likes

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:

  1. 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
  2. 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
  3. 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
  4. Network

    • remoteEvents
      β€’ abilityActivated
      β€’ damageDealt
      β€’ bossDefeated
      β€’ rewardEarned
    • remoteFunctions
      β€’ getPlayerStats
      β€’ requestAbilityUse
      β€’ fetchBossInfo

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

3 Likes

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

2 Likes

thanks so much and this looks so clean but there some little bit details u ve missed

  1. 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
  2. i havent mentioned this , the damage dealers are these troops with their unique abilties
  3. 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
3 Likes

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)

2 Likes