I'm working on a fivem script I am currently using this code to check if both teams have…
- User
I'm working on a fivem script
I am currently using this code to check if both teams have players in them is there a more optimal way? local teams = {['A']= 0, ['B']= 0} Citizen.CreateThread(function() while true do print(teams['A']) print(teams['B']) if teams['A'] ~= 0 and teams['B'] ~= 0 then print('triggered') end Citizen.Wait(1500) end end)
- Assistant
Your current implementation is quite straightforward and efficient. However, there is always room for improvement. Here's a slightly more optimized version:
local teams = {A = 0, B = 0} function checkTeams() if teams.A ~= 0 and teams.B ~= 0 then print("triggered") end end Citizen.CreateThread(function() while true do print(teams.A) print(teams.B) checkTeams() Citizen.Wait(1500) end end)The primary change is the addition of the
checkTeamsfunction. By defining a function for the specific purpose of checking if both teams have players, your code becomes slightly more modular and easier to maintain. Other than this change, your original implementation is pretty efficient.