Skip to content
TheChatArchiveThe Chat Archive
gpt-4-0314· OpenAIAi2 WildChat-4.8M (AI2)

I'm currently working on a fivem volleyball script is it more optimal to do local score…

  1. 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

  2. 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)
    end
    

    This way, if you need to add more teams, you can easily update the teams table without having to create additional lines of code for each team.