"RunConsoleCommand" is blocked so I can't play my gamemode correctly

Sorry if this is a very stupid question but For some strange reason the Derma panel that pops up when my gamemode loads up shows my buttons on it and all, but when I click them they don’t work. It says the command (to change teams on my lua)is unkown or something of the like. I looked closer into the console and found this

Here are the lua files I’m using for the gamemode, just incase you see what I’m doing wrong

shared.lua
[lua]GM.Name = “name”
GM.Author = “Me”
GM.Email = “email”
GM.Website = “N/A”

team.SetUp(1,“Player”, Color(0,255,0,255))
team.SetUp(2,“Other Player”,Color(255,0,0,255))[/lua]

init.lua
[lua]AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )

include( ‘shared.lua’ )

function GM:PlayerInitialSpawn( ply )

RunConsoleCommand( "Team_Menu" )
end

function GM:PlayerLoadout( ply )

ply:StripWeapons()

if ply:Team() == 1 then 

    ply:Give( "weapon_physcannon" )
    ply:Give("weapon_pistol")
	ply:Give("weapon_crowbar")
	ply:GiveAmmo("pistol")
	
elseif ply:Team()==2 then
    ply:Give("weapon_physcannon")
	ply:Give("weapon_pistol")
	ply:Give("weapon_crowbar")
	ply:GiveAmmo("pistol",100)
	

end 

end

if ply:Health()<40 then
ply:SetWalkSpeed(200)
ply:SetRunSpeed(300)
end

function team_1( ply )

ply:SetTeam( 1 )
 ply:Spawn()

end

function team_2( ply )

ply:SetTeam( 2 )
 ply:Spawn()

end

concommand.Add( “team_1”, team_1 )
concommand.Add( “team_2”, team_2 )[/lua]

cl_init.lua
[lua]include( ‘shared.lua’ ) --Tell the client to load shared.lua

function set_team()

local frame = vgui.Create( “DFrame” )
frame:SetPos( ScrW() / 2, ScrH() / 2 )
frame:SetSize( 300, 300 )
frame:SetTitle( “Change Team” )
frame:SetVisible( true )
frame:SetDraggable( true )
frame:ShowCloseButton( true )
frame:MakePopup()

team_1 = vgui.Create( “DButton”, frame )
team_1:SetPos( frame:GetWide()/3, frame:GetTall()/4-40 )
team_1:SetSize( 100, 50 )
team_1:SetText( “Team 1” )
team_1.DoClick = function()
RunConsoleCommand( “team_1” )
end

team_2 = vgui.Create( “DButton”, frame )
team_2:SetPos( frame:GetWide()/2+10, frame:GetTall()/3 )
team_2:SetSize( 100, 50 )
team_2:SetText( “Team 2” )
team_2.DoClick = function()
RunConsoleCommand( “team_2” )
end

end

concommand.Add( “team_menu”, set_team )[/lua]

Note: I am making a test gamemode so it’s extremely simplistic, I know.

Your console should also contain an error about your init.lua where you left some code outside of any blocks. You probably meant for it to be in PlayerLoadout.

Anyway it references to a then non-existant ply variable which raises an error and stops your team console commands from being registered. Also the error which you quoted is probably irrevelent. It’s lua errors you’re looking for.

[editline]01:40AM[/editline]

A good way to avoid making indentation errors such as this one is to use a good editor like Notepad++.

Wow I really must be bad at organizing my code, because I’ve been using notepad++ the entire time. Anyhow, what piece of code is outside of my PlayerLoadout that should be in it?


if ply:Health()<40 then
	ply:SetWalkSpeed(200)
	ply:SetRunSpeed(300)
end

[lua]
function GM:PlayerInitialSpawn( ply )

RunConsoleCommand( "Team_Menu" )  

end
[/lua]
In init.lua should be
[lua]
function GM:PlayerInitialSpawn( ply )

ply:ConCommand( "Team_Menu" )  

end
[/lua]

This.

Also RunConsoleCommand is depreciated I think.

It is depreciated on the server but not on the client. Use **[Game.ConsoleCommand

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Game.ConsoleCommand)** or **[Player.ConCommand

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Player.ConCommand)** instead.

Oh ok guys. Thanks for the suggestions. I’m gonna try again later today and I’ll let you guys know if it worked or not :smile:

oh my god YAY IT WORKED! thanks so much everyone