Limit charater chat

hello all !
Possible limit character in chat Fxserver ?
thank you so much for reponse !

Server Script:

AddEventHandler('chatMessage', function(s, n, m) -- chat message handler
    msg = string.len(m) -- counts the amount of characters in the user's message
    
    if (msg > 20) then -- checks if the user's message is longer than the max characters (20 in this case)
        CancelEvent() -- stops the original message to be send, allowing for a callback
        TriggerClientEvent('chatMessage', s, 'SYSTEM', {255, 0, 0}, 'Message too long!') -- displays a callback for the user, stating their message was too long
    else
        CancelEvent() -- this doesn't need to be here, but I put it before everything just for future proofing.
        TriggerClientEvent('chatMessage', -1, n, {10, 240, 10}, m) -- sends the user's message (m) to the whole server (-1) 
    end
    
end)

Very basic, the “20” in the if statement will be your max characters allowed.

If you run into any problems let me know

2 Likes

Nice job Thank you so much !

its possible lock written 50 character on client ?

Yes. Just change if (msg > 20) then to if (msg > 50) then

hello thank,
no just before reaches the server.:frowning_face:

Not sure what you mean, sorry.