/me not working with proximity

So I have this code so far…

RegisterNetEvent('sendProximityMessageMe')
AddEventHandler('sendProximityMessageMe', function(id, name, message)
  local myId = PlayerId()
  local pid = GetPlayerFromServerId(id)
  local playerPed = PlayerPedId()
  if pid == myId then
    TriggerEvent('chatMessage', "[".. id .."] me" .. "", {251, 53, 37}, "^7 " .. message)
  elseif GetDistanceBetweenCoords(GetEntityCoords(GetPlayerPed(myId)), GetEntityCoords(GetPlayerPed(pid)), true) < 19.999 then
    TriggerEvent('chatMessage', "[".. id .."] me" .. "", {251, 53, 37}, "^7 " .. message)
  end
end)

Server:

 AddEventHandler('chatMessage', function(source, name, message)
      if string.sub(message, 1, string.len("/")) ~= "/" then
		  local name = GetPlayerName(source)
		TriggerClientEvent("sendProximityMessage", -1, source, name, message)
      end
      CancelEvent()
  end)

Is working but /me and all commands are appearing for everyone in the server

same here, any solutions for this ?

Changing the onesync enabled in cfg to onesync legacy and started working

Alternately, fix your script!

  elseif GetDistanceBetweenCoords(GetEntityCoords(GetPlayerPed(myId)), GetEntityCoords(GetPlayerPed(pid)), true) < 19.999 then

pid can be -1 if the player doesn’t exist which will always show, you should first check if pid is -1.

1 Like

I’m thinking in something like this maybe ?

RegisterNetEvent('sendProximityMessageMe')
AddEventHandler('sendProximityMessageMe', function(id, name, message)
  local myId = PlayerId()
  local pid = GetPlayerFromServerId(id)
  local playerPed = PlayerPedId()
  local falsepid = -1
  if pid == falsepid then
   (Idk what to put in here xd)
  elseif pid == myId then
    TriggerEvent('chatMessage', "[".. id .."] me" .. "", {251, 53, 37}, "^7 " .. message)
  elseif GetDistanceBetweenCoords(GetEntityCoords(GetPlayerPed(myId)), GetEntityCoords(GetPlayerPed(pid)), true) < 19.999 then
    TriggerEvent('chatMessage', "[".. id .."] me" .. "", {251, 53, 37}, "^7 " .. message)
  end
end)