Get player ID from aiming

Hi!

Im trying to get a players ID by aiming at them with a weapon, however im not sure how to get the players ID from the entity id received when using GetEntityPlayerIsAimingAt()

I have this code currently:

local ped = GetPlayerPed(-1)
		local aiming, entity = GetEntityPlayerIsFreeAimingAt(PlayerId())
		if IsControlJustPressed(1, myKey) then
			if aiming then
					if not IsEntityAVehicle(entity) then
						local target = GetPlayerPed(entity)
						local target_id = GetPlayerServerId(target) 
						
						local tx, ty, tz = table.unpack(GetEntityCoords(entity, true))
						local px, py, pz = table.unpack(GetEntityCoords(ped, true))
						if GetDistanceBetweenCoords(px, py, pz, tx, ty, tz, true) <= 5 and GetDistanceBetweenCoords(px, py, pz, tx, ty, tz, true) > -1 then
							TriggerEvent("chatMessage", "SYSTEM:", {255, 0, 0},  target_id)
							
						elseif GetDistanceBetweenCoords(px, py, pz, tx, ty, tz, true) < 20 and GetDistanceBetweenCoords(px, py, pz, tx, ty, tz, true) > 5 then
							
							ESX.ShowNotification("You are too far")
						else
							ESX.ShowNotification("There are no players")
						end
					else
						ESX.ShowNotification("There are no players")
					end
			else
				ESX.ShowNotification("You must be aiming")
			end
		end

Any help would be appreciated.

Thank you