Addon Help Please.

Hello Facepunch,

I’m trying to make a dice system when someone says /roll and they’re looking at someone it’ll chat print what they’ve rolled but it seems it only prints for the client itself and not the player who you’re looking at also.

So when I roll it says “tom rolled 20” as an example but it only shows for me, it should show for the person I’m looking at too.

[LUA]
– SERVER

dicenum = 0
util.AddNetworkString(“sending_user_msg”)

hook.Add( “PlayerSay”, “RTD_rollthedice_addon_ttmy”, function( ply, text, public )
text = string.lower( text ) – Make the chat message entirely lowercase
if ( text == “/roll” ) then

	_dice = math.random(1, 100)

	net.Start("sending_user_msg")
	net.WriteInt(_dice, 22)
	net.Send(ply)

	
	return ""
end

end )

– CLIENT

local plr = LocalPlayer()
net.Receive(“sending_user_msg”, function(len)

local diceRead = net.ReadInt(22)

local trace = plr:GetEyeTrace()
local ent = trace.Entity

if plr:IsValid() && (ent:GetClass()=="player") then

	chat.AddText( plr:Nick().." rolled "..diceRead )

else

	chat.AddText("You need to look at someone.")
end

end)

[/LUA]

Please help, I can’t seem to find a solution.

:snip:
Use the IsPlayer check on the PlayerSay hook, this way you can send it to both players

[editline]edit[/editline]
I just looked at the whole script, you seem to have quite a few problems.
First of all, net.WriteInt only takes 1 argument, which is the integer. And net.ReadInt take no arguments. It reads and writes from/to the net message that is being sent/received.
Also, plr seems to be undefined? LocalPlayer() is what you should use on the client
One more thing: You have global variables for no reason. When making a variable (e.g. _dice) put the word ‘local’ before it, global variables are rarely necessary (And certainly aren’t for this scenario)

Hi, you have looking this ? http://steamcommunity.com/sharedfiles/filedetails/?id=515482900
or this is better http://steamcommunity.com/sharedfiles/filedetails/?id=516377504