I've been working on making commands for a gamemode. I've made a roll command that prints this to the console:
[quote](Name of player) has rolled a (Number: 0 through 100) out of 100.[/quote]
The printing to console works perfectly with no errors. However, the issue is that my game says that "Chat" is a nil value.
[quote][lua\autorun\consolecommand.lua:4] attempt to index global 'Chat' (a nil value)[/quote]
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".
[quote][lua\autorun\consolecommand.lua:4] attempt to index global 'chat' (a nil value)[/quote]
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.
Sorry, you need to Log In to post a reply to this thread.