Error when trying to create /me handler

chat
serverside
clientside
textchat

#1

Heyo

So the thing is im trying to learn some Lua and I would like to try to make a custom /me [text] command with proximity but so far I’ve got to where I need to check the user if he or she is in range.

My code is as follows.

Server.lua

AddEventHandler('chatMessage', function(source, name, msg)
    sm = stringsplit(msg, " ");
    if sm[1] == "/me" then
        CancelEvent()
        TriggerClientEvent('sendMeMessage', source, msg)
    end
end)

function stringsplit(inputstr, sep)
    if sep == nil then
        sep = "%s"
    end
    local t={} ; i=1
    for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
        t[i] = str
        i = i + 1
    end
    return t
end

Client.lua

RegisterNetEvent('sendMeMessage')
AddEventHandler("sendMeMessage", function(id, msg)
local x,y,z = table.unpack(GetEntityCoords(GetPlayerPed(id),true))
    for i = 0, 31 do

        if NetworkIsPlayerActive(i) then

        if GetDistanceBetweenCoords(GetEntityCoords(GetPlayerPed(id)), GetEntityCoords(GetPlayerPed(i)), true) < 19.999 then
            TriggerClientEvent('chatMessage', i, "me- ", {255, 0, 0}, msg )
        end

        end
    end

end)

All help is appreciated and I would love here ideas and such.