Chat.AddText Issue

I’ve been working on making commands for a gamemode. I’ve made a roll command that prints this to the console:

The printing to console works perfectly with no errors. However, the issue is that my game says that “Chat” is a nil value.

This is the code so far:

[lua]concommand.Add( “FWRP_roll”, function(ply)

print( ply:Name() … " has rolled a " … math.random(0,100) … " out of 100.")
Chat.AddText (Color(0,0,255), ply:Name() … " has rolled a " … math.random(0,100) … " out of 100.")

end )[/lua]

You have “Chat” capitalized. The function call is “chat.AddText” - capitalization matters =P

Nothing has changed after I made it “chat.AddText”.

The code looks like this now:

[lua]concommand.Add( “FWRP_roll”, function(ply)

print( ply:Name() … " has rolled a " … math.random(0,100) … " out of 100.")
chat.AddText (Color(0,0,255), ply:Name() … " has rolled a " … math.random(0,100) … " out of 100.")

end )[/lua]

Edit:

I even tried out the wiki’s example which ended in the same exact result.

Based on where you have the file, it looks like it’s being called on both the client and the server. Either surround that in an “if CLIENT then … end” or move it to lua\autorun\client.

It now works after I moved the file to autorun/client. Thanks for the help.

The problem is it would only show up clientsidedly when someone uses the command, so do the above and use if ( CLIENT ) then chat.AddText().

By the way, you’re making a game mode, why are you putting the commands in the auto run directory?

Ps, it’s me, ~CN.