[Solved] NUI JS event never called?

Hey there,

I have issues setting up a simple GUI with NUI, here’s my JS code :

window.addEventListener('message', function(event) {
	if (event.data.updateHUD == true) {
		$('#Balance').text(event.data.Balance);
	}
});

Yes, I also checked if my HTML has the right id.
And here’s my lua script :

SendNUIMessage({ updateBalance = true, Balance = values.Balance["balance"] })

I’ve checked if the script is called by adding console debugging after this line, it’s called. No error.
I’ve checked if values.Balance["balance"] is not nil, it isn’t.

Any idea ?

Thanks

Replace event.data.updateHUD per event.data.updateBalance
or create elseif

if (event.data.updateHUD == true) {
    // in jQuery = $('MeHUD').css('display', 'block');
}
elseif (event.data.updateBalance == true) {
$('#Balance').text(event.data.Balance);
// or $('#Balance').html(event.data.Balance);
}

Tuto for HTML ui and lua
https://forum.cfx.re/t/how-to-use-nui-ui-creation-with-html/1127

2 Likes

Indeed, obvious mistake ahah. Cheers mate !

1 Like