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.


dicenum = 0

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.WriteInt(_dice, 22)

	return ""

end )


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 )


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



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

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

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 ?
or this is better