Hello, so I’m fairly new to writing my own Lua scripts but I have done some modding of existing scripts to be functional and the like, so bare with that. I am trying to make a BAC script where a user can set a BAC by clicking a button in one of my menus, and a text box opens to enter in the BAC. The below event gets triggered when the user clicks the button. It is not getting to the “chatMessage” event so I’m assuming there is something wrong with how I am using the source variable(not entirely sure this is the correct way to go about that either). Below the code is an image of the error I get as well. “Table index is nil”- I think the source is the cause and not actually grabbing the user that’s entering in the BAC
Thanks for any help.
----------------BAC Code-----------------------
bac = {}
RegisterNetEvent('SetBAC')
AddEventHandler('SetBAC', function(source)
DisplayOnscreenKeyboard(1, "FMMC_MPM_NA", "", "", "", "", "", 30)
while (UpdateOnscreenKeyboard() == 0) do
DisableAllControlActions(0);
Wait(0);
end
if (GetOnscreenKeyboardResult()) then
local result = GetOnscreenKeyboardResult()
bac[source] = result
TriggerClientEvent('chatMessage', source, "Breathalyzer", {47, 121, 239}, "BAC set to: "..bac[source])
end
end )
