Problem with net library

Hello,
I’m making a logging system, it’s all working, but I’m having constantly problems with the net library.
This is something I’m having problems with:


net.Receive("KickPlayer",function(l,pl)
	local id = net.ReadEntity():UserID()
	local res = net.ReadString()
	if pl:IsSuperAdmin() or pl:IsAdmin() then
	player.GetByID(id):Kick(res)
	end
end)

(Note: I have used util.AddNetworkString)

When I do this, it thinks net.ReadEntity() is nil.
Here’s my code clientside:

(My code looks a lot better in my editor)




function getPlayerFromSteamID(steamid)
local returnEnt = nil
for _,v in pairs(player.GetAll()) do
if v:SteamID() == steamid then
returnEnt = v
end
end
return returnEnt
end

	kik.DoClick = function()
		if selectedPlayerSteamID ~= nil then
			surface.PlaySound("buttons/button9.wav")
			Derma_StringRequest("Kicking Player","Specify a reason","Reason",function(res)
			surface.PlaySound("buttons/button9.wav")
			if getPlayerFromSteamID(selectedPlayerSteamID) ~= nil then
				notification.AddLegacy("Kicked player "..getPlayerFromSteamID(selectedPlayerSteamID):Nick().." from the server!",NOTIFY_GENERIC,5)
				net.Start("KickPlayer")
				net.WriteEntity(getPlayerFromSteamID(selectedPlayerSteamID))
				net.WriteString(res)
				net.SendToServer()
			else
				notification.AddLegacy("Could not find player with SteamID "..selectedPlayerSteamID.." in server!",NOTIFY_ERROR,3)
				surface.PlaySound("buttons/button8.wav")
			end
			end)
		else
			surface.PlaySound("buttons/button8.wav")
		end
	end

But why does this have a problem? I don’t know if it’s even POSSIBLE for an entity to be 64 kilobytes and I’m guessing I’m doing everything correctly, so what’s wrong?
Thank you :stuck_out_tongue:

The way WriteEntity works is that it should send a number which is then converted back on the other side. I’ve noticed many many many times the same issue. The way I get around is it by sending a number of Player:EntIndex( ) to the receiving side, then you turn it into an entity by using Entity( Player:EntIndex( ) )

net.WriteLong( Player:EntIndex( ) )

Entity( net.ReadLong( ) )

I’m not sure if Long works, or if you need to use one of the other number formats; give it a shot.

I fixed it. It must have been a problem with my getPlayerFromSteamID function. (I don’t trust functions with long names).
I just rewrote the code (which was almost exactly the same) and for some reason it actually worked this time!