Problem with Net message...

I have a simple Derma menu where a player can select another player from a list, and make the selected player VIP.
When the player is selected, and a button is pressed, the selected players SteamID gets sent to the server.
However, somehow, that string (the SteamID) get’s corrupted underway.

Brace for impact!:

Serverside



net.Receive("fp_don_makeDonator", function(_,ply)

	local elite = net.ReadBool()
	local targetSID = net.ReadString()
	local target
	
	print("Serverside SteamID: "..targetSID)
	
	for _,v in ipairs(player.GetAll()) do
	
		if v:SteamID() == targetSID then
			
			target = v
			
		else
		
			print("Player not found!")
			
		end
	
	end
	
	if not elite then
	
		ULib.ucl.addUser(targetSID,{},{},i_vip["rank"])
		target:addMoney(i_vip["money"])
	
	else
	
		ULib.ucl.addUser(targetSID,{},{},i_vip["rank"])
		target:addMoney(i_elitevip["money"])
	
	end

end)


Clientside



net.Receive("fp_don_openMenu", function()
	
	local dlv = vgui.Create("DListView", dp)
	dlv:SetMultiSelect(false)
	dlv:AddColumn("Index")
	dlv:AddColumn("Name")
	dlv:AddColumn("SteamID")
	
	local count = 1
	local plyIndex = {}
	
	for _,v in ipairs(player.GetAll()) do

			dlv:AddLine(count, v:Nick(), v:SteamID())
			table.insert(plyIndex, count, v)
			count = count + 1
	
	end
	
	dlv:SetPos(5,80)
	dlv:SetSize(300,300)
	
	local db = vgui.Create("DButton", dp)
	db:SetText("Apply Donator")
	db:SetPos(200,50)
	db:SetSize(200,100)
	db.DoClick = function()
		local tarSID = tostring( plyIndex[dlv:GetSelectedLine()]:SteamID() )
		
		print("Clientside SteamID: "..tarSID)
		
		net.Start("fp_don_makeDonator")
			net.WriteString(tarSID)
			net.WriteBool(dcb:GetChecked())
		net.SendToServer()
	end

end)


Console



Clientside SteamID: STEAM_0:0:36773027
Serverside SteamID: )����/�����e
Player not found!

[ERROR] addons/darkrpmodification/lua/darkrp_modules/fp_donator/sv_donator.lua:47: attempt to index local 'target' (a nil value)
  1. func - addons/darkrpmodification/lua/darkrp_modules/fp_donator/sv_donator.lua:47
   2. unknown - lua/includes/extensions/net.lua:32




(yes, those “?”-boxes are actually displayed as “?”-boxes in the console)

Any help is appreciated :smiley:

  • FP

You are reading in the wrong order.


)Serverside SteamID: )����/�����

Also,


local target


attempt to index local 'target' (a nil value)


local target = nil

?


for _,v in ipairs(player.GetAll()) do
	
if v:SteamID() == targetSID then
target = v
else
print("Player not found!")
end

end

You should use this instead. Because if you don’t. It will spam you “Player not found!”.


for _,v in ipairs(player.GetAll()) do
if v:SteamID() == targetSID then
target = v
end
end

if target == nil then
print("Player not found!")
else
-- continue the script
end


table.insert(plyIndex, count, v)

Why not:


table.insert(plyIndex, count, v:SteamID())

then:


local tarSID = plyIndex[dlv:GetSelectedLine()]

Thanks a lot guys!

Because I initially wanted to do this:


table.insert(plyIndex, count, v)

And then:


		net.Start("fp_don_makeDonator")
			net.WriteEntity(plyIndex[dlv:GetSelectedLine()])
			net.WriteBool(dcb:GetChecked())
		net.SendToServer()

And that now works :smiley:

Verify your net messages, with that anyone can make people donator.

[lua] net.Start(“fp_don_makeDonator”)
net.WriteEntity(LocalPlayer())
net.WriteBool(true)
net.SendToServer()[/lua]

oh my

this is how normal people send localplayer