im fairly new to lua and working on CFX FiveM, and have made a simple table.insert which calls on a for type, value in pairs(Config.Skills) do This is then refering back to a SQL table which is pulling the data correctly, but the table inserts are showing the same value.
SQL OUTPUT - {"stamina":{"RemoveAmount":-0.3,"Stat":"MP0_STAMINA","Current":25},"strength":{"RemoveAmount":-0.3,"Current":13,"Stat":"MP0_STRENGTH"}}
Lua Code
function SkillMenu()
FetchSkills()
Wait(1000)
RefreshSkills()
local elements = {}
for type, value in pairs(Config.Skills) do
table.insert(elements, {
type = 'button',
name = "stamina",
label = "Stamina",
description = type .. value["Current"] .. "%",
icon = 'fad fa-heartbeat',
disabled = true
})
table.insert(elements, {
type = 'button',
name = 'strength',
label = "Strength",
description = type .. value["Current"] .. "%",
icon = 'fad fa-heartbeat',
disabled = true
})
TMC.Functions.OpenMenu({
namespace = "skillmenu",
type = 'openMenu',
title = "Skill menu",
}, elements, function(close, confirmed)
end, function(selected)
end, function(change)
if change.elementChanged == "stamina" then
TMC.Functions.CloseMenu()
elseif change.elementChanged == 'strength' then
TMC.Functions.CloseMenu()
end
end)
end
end
What I am looking to achieve:
Stamina stamina25%
Strength strength13%
Thanks in advance
The problem is that you're doing both
table.inserts in both iterations, but you should only be creating each menu item once. Either wrap yourtable.inserts inifstatements so they only run for the correct iteration, or just remove the loop altogether and use expressions likeConfig.Skills.stamina.CurrentandConfig.Skills.strength.Currentto get the values.