gpt-4-0314· OpenAI
WildChat-4.8M (AI2)
I'm currently working on a fivem volleyball script is it more optimal to do local score…
- User
I'm currently working on a fivem volleyball script
is it more optimal to do local score = {['TeamA'] = 0, ['TeamB'] = 0} TriggerClientEvent("qb-nui:update-score", score['TeamA'], formattedScore) TriggerClientEvent("qb-nui:update-score", score['TeamB'], formattedScore)
or with a for loop local score = {['TeamA'] = 0, ['TeamB'] = 0}
for k,v in teams do TriggerClientEvent("qb-nui:update-score", v, formattedScore) end
- Assistant
It's more optimal to use a for loop as it provides flexibility if you need to add more teams in the future. Here's the corrected code:
local score = {['TeamA'] = 0, ['TeamB'] = 0} local teams = {'TeamA', 'TeamB'} for _, team in ipairs(teams) do local formattedScore = tostring(score[team]) TriggerClientEvent("qb-nui:update-score", team, formattedScore) endThis way, if you need to add more teams, you can easily update the
teamstable without having to create additional lines of code for each team.