Problem with a serverside function

I am trying to make a button that gets the player UserID and kills him. How I get the userID is not important because it works. But I get this error


attempt to call method 'Kill' (a nil value)



//CLIENT side code
local kill = vgui.Create("DButton")
		kill:SetParent(items)
		kill:SizeToContents()
		kill:SetSize(10,30)
		kill:SetText("Kill Player")
		kill.DoClick = function()
			if(pplTable:GetLine(pplTable:GetSelectedLine()):GetValue(4) == "") then
				print(HUD_PRINTTALK, "Could not find player. Or you didn't select one. Dummy.")
			else
				net.Start("kill")
				net.WriteFloat(pplTable:GetLine(pplTable:GetSelectedLine()):GetValue(4))
				net.SendToServer()
			end
		end
		items:AddItem(kill)




//SERVER side code
util.AddNetworkString("kill")
	net.Receive( "kill", function()    
		MsgN("ReadFloat:")
		MsgN(net.ReadFloat())  
		Player(tonumber(net.ReadFloat())):Kill()
		//Player(8):Kill()
	end)


When I switch the lines between “//Player(8):Kill()” and “Player(tonumber(net.ReadFloat())):Kill()” it works. I have no idea why it is not working.

Also when in I do in console “lua_run Player(8):Kill()” it works too.

You are reading it twice. The second time it reads it it won’t get anything or will get random junk. You need to read the values in the order you wrote them, and if you want to use them again you need to store them in a variable.



//SERVER side code
util.AddNetworkString("kill")
	net.Receive( "kill", function()    
		MsgN("ReadFloat:")
		local num = net.ReadFloat()
		MsgN(num )  
		Player(num):Kill()
	end)


If you are just sending player ids then use WriteInt instead of WriteFloat (its a small difference but less impact on the network). And either way, when you read it you are guaranteed to get the type you want, there is no need to use tonumber() on it.

Oh thanks.