[Help] Nui to everyone on the server

Hey guys how would i go about sending a nui to everyone. A tweet for example /tweet sends message and your name to nui but how would i stream to all on the server.
Any help would be appreciated.

Client entering tweet -> TriggerServerEvent with tweet data.
Server Event Handler -> TriggerClientEvent using -1 to go to all Clients with tweet data.
Clients Event Handler -> SendNUIMessage with tweet data

1 Like

please can you give me an example of code

server script

RegisterCommand('tweet', function(source, args, raw)
    if not args[1] then
        return
    else
        TriggerClientEvent('tweet:new', -1, {name=GetPlayerName(source), tweet=table.concat(args, ' ')})
    end
end, false)

client script

RegisterNetEvent('tweet:new')
AddEventHandler('tweet:new', function(tweetData)
    SendNUIMessage({
        type="tweet",
        tweetData=tweetData
    })
end)

nui html, javascript, css omitted.

For help with this see: [How-To] Use NUI (UI Creation with HTML)

thanks


hey i got this error when i done the command

The RegisterCommand part goes in a server script, not a client script. I did it that way to reduce the overhead since if you register the command in the client you’re going to have to trigger the server to trigger the other clients anyways. This does same with less overhead.