Script partially working on local, but completely failing on a dedicated server

I’m not exactly new to Lua, but it’s my first time using Derma properly(I think). Now I’m not getting any error messages in either server, but on the dedicated server my commands refuse to register. Could it be the way I have my code set up and what not?

Here’s the script:



function mainmenu()

local MainMenu
local SpawnIcon1FIDG
local SpawnIcon1EETM
local SpawnIcon1
local RpDesc
local RpName3
local DLabel3
local RpName2
local Start

MainMenu = vgui.Create('DFrame')
MainMenu:SetSize(481, 694)
MainMenu:SetPos(272, 12)
MainMenu:SetTitle('Welcome to Vanilla!')
MainMenu:SetSizable(true)
MainMenu:SetDeleteOnClose(false)
MainMenu:SetBackgroundBlur(true)
MainMenu:MakePopup()

SpawnIcon1FIDG = vgui.Create('SpawnIcon',MainMenu)
SpawnIcon1FIDG:SetPos(179, 83)
SpawnIcon1FIDG.OnMousePressed = function( icon ) surface.PlaySound( "ui/buttonclickrelease.wav" ) RunConsoleCommand("rp_setmodel","models/players/perp2suit/male_03.mdl") end
SpawnIcon1FIDG:SetModel('models/players/perp2suit/male_03.mdl')

SpawnIcon1EETM = vgui.Create('SpawnIcon',MainMenu)
SpawnIcon1EETM:SetPos(115, 83)
SpawnIcon1EETM.OnMousePressed = function( icon ) surface.PlaySound( "ui/buttonclickrelease.wav" ) RunConsoleCommand("rp_setmodel1","models/players/perp2suit/male_04.mdl") end
SpawnIcon1EETM:SetModel('models/players/perp2suit/male_04.mdl')

SpawnIcon1 = vgui.Create('SpawnIcon',MainMenu)
SpawnIcon1:SetPos(51, 83)
SpawnIcon1.OnMousePressed = function( icon ) surface.PlaySound( "ui/buttonclickrelease.wav" ) RunConsoleCommand("rp_setmodel2","models/players/humans/group01/clo4fe_01.mdl") end
SpawnIcon1:SetModel('models/players/humans/group01/clo4fe_01.mdl')

RpDesc = vgui.Create('DLabel',MainMenu)
RpDesc:SetPos(51, 627)
RpDesc:SetText('Description')
RpDesc:SizeToContents()

RpDescrip = vgui.Create('DTextEntry',MainMenu)
RpDescrip:SetSize(158, 20)
RpDescrip:SetPos(116, 623)
RpDescrip.OnEnter = function() end

RpName3 = vgui.Create('DLabel',MainMenu)
RpName3:SetPos(51, 652)
RpName3:SetText('Job')
RpName3:SizeToContents()

RpJob = vgui.Create('DTextEntry',MainMenu)
RpJob:SetSize(158, 20)
RpJob:SetPos(116, 648)
RpJob.OnEnter = function() end

DLabel3 = vgui.Create('DLabel',MainMenu)
DLabel3:SetPos(45, 47)
DLabel3:SetText('Please select a player model! This will represent your character in-game!')
DLabel3:SizeToContents()

RpName2 = vgui.Create('DLabel',MainMenu)
RpName2:SetPos(51, 678)
RpName2:SetText('Set an RP Name')
RpName2:SizeToContents()

RPName = vgui.Create('DTextEntry',MainMenu)
RPName:SetSize(158, 22)
RPName:SetPos(115, 673)
RPName.OnEnter = function() end

Start = vgui.Create('DButton',MainMenu)
Start:SetSize(95, 28)
Start:SetPos(158, 670)
Start:SetText('Start')
Start.DoClick = function() end
end

concommand.Add("rp_mainmenu",mainmenu)

function setmodel(ply)
        ply:SetModel("models/players/perp2suit/male_03.mdl")	
end
concommand.Add("rp_setmodel",setmodel)

function setmodel2(ply)
        ply:SetModel("models/players/perp2suit/male_04.mdl")	
end
concommand.Add("rp_setmodel1",setmodel2)

function setmodel3(ply)
        ply:SetModel("models/players/humans/group01/clo4fe_01.mdl")	
end
concommand.Add("rp_setmodel2",setmodel3)

Any help with this would be greatly appreciated, I’d just like to get it working on the dedicated server so I can continue work.

Make sure this code is clientside, and you send it to the client via AddCSLuaFile (<LuaPath>) and include on the client.

The code is clietnside, but I have a feeling that



function setmodel(ply)
        ply:SetModel("models/players/perp2suit/male_03.mdl")	
end
concommand.Add("rp_setmodel",setmodel)

function setmodel2(ply)
        ply:SetModel("models/players/perp2suit/male_04.mdl")	
end
concommand.Add("rp_setmodel1",setmodel2)

function setmodel3(ply)
        ply:SetModel("models/players/humans/group01/clo4fe_01.mdl")	
end
concommand.Add("rp_setmodel2",setmodel3)

Shouldn’t be included in this then and rather kept serverside?

Yes, those concomands should be server side.

Thanks for the help. Gonna test this out ASAP.

[editline]8th January 2011[/editline]

Well, it works now. Time to move forward. Thanks guys.

Updated script:


function mainmenu()

local MainMenu
local SpawnIcon1FIDG
local SpawnIcon1EETM
local SpawnIcon1
local RpDesc
local RpName3
local DLabel3
local RpName2
local Start

MainMenu = vgui.Create('DFrame')
MainMenu:SetSize(481, 694)
MainMenu:SetPos(272, 12)
MainMenu:SetTitle('Welcome to Vanilla!')
MainMenu:SetSizable(true)
MainMenu:SetDeleteOnClose(false)
MainMenu:SetBackgroundBlur(true)
MainMenu:MakePopup()

SpawnIcon1FIDG = vgui.Create('SpawnIcon',MainMenu)
SpawnIcon1FIDG:SetPos(179, 83)
SpawnIcon1FIDG.OnMousePressed = function( icon ) surface.PlaySound( "ui/buttonclickrelease.wav" ) RunConsoleCommand("rp_setmodel","models/players/perp2suit/male_03.mdl") end
SpawnIcon1FIDG:SetModel('models/players/perp2suit/male_03.mdl')

SpawnIcon1EETM = vgui.Create('SpawnIcon',MainMenu)
SpawnIcon1EETM:SetPos(115, 83)
SpawnIcon1EETM.OnMousePressed = function( icon ) surface.PlaySound( "ui/buttonclickrelease.wav" ) RunConsoleCommand("rp_setmodel1","models/players/perp2suit/male_04.mdl") end
SpawnIcon1EETM:SetModel('models/players/perp2suit/male_04.mdl')

SpawnIcon1 = vgui.Create('SpawnIcon',MainMenu)
SpawnIcon1:SetPos(51, 83)
SpawnIcon1.OnMousePressed = function( icon ) surface.PlaySound( "ui/buttonclickrelease.wav" ) RunConsoleCommand("rp_setmodel2","models/players/humans/group01/clo4fe_01.mdl") end
SpawnIcon1:SetModel('models/players/humans/group01/clo4fe_01.mdl')

RpDesc = vgui.Create('DLabel',MainMenu)
RpDesc:SetPos(51, 590)
RpDesc:SetText('Description')
RpDesc:SizeToContents()

RpDescrip = vgui.Create('DTextEntry',MainMenu)
RpDescrip:SetSize(158, 20)
RpDescrip:SetPos(116, 586)
RpDescrip.OnEnter = function() end

RpName3 = vgui.Create('DLabel',MainMenu)
RpName3:SetPos(51, 620)
RpName3:SetText('Job')
RpName3:SizeToContents()

RpJob = vgui.Create('DTextEntry',MainMenu)
RpJob:SetSize(158, 20)
RpJob:SetPos(116, 614)
RpJob.OnEnter = function() end

DLabel3 = vgui.Create('DLabel',MainMenu)
DLabel3:SetPos(45, 47)
DLabel3:SetText('Please select a player model! This will represent your character in-game!')
DLabel3:SizeToContents()

RpName2 = vgui.Create('DLabel',MainMenu)
RpName2:SetPos(42, 648)
RpName2:SetText('Set an RP Name')
RpName2:SizeToContents()

RPName = vgui.Create('DTextEntry',MainMenu)
RPName:SetSize(158, 22)
RPName:SetPos(116, 644)
RPName.OnEnter = function() end

Start = vgui.Create('DButton',MainMenu)
Start:SetSize(95, 28)
Start:SetPos(290, 640)
Start:SetText('Start')
Start.DoClick = function() end
end

concommand.Add("rp_mainmenu",mainmenu)


Broken again somehow, no idea whats wrong with it this time and several people have told me that it shouldn’t be broken.

the error is:
Attempt to index global ‘vgui’(a nil value) on line 15.

Are you definitely doing this clientside?

it’s all in the cl_init.lua file, so it should be client side.

Shouldn’t you use at beginning of code include(“pathhere.lua”)

Someone told me this earlier today, I still have troubles with clientside derma even though I know what to do and how. Just doesn’t like me

It’s there, i was just posting a snippet of my cl_init.lua file

[editline]8th January 2011[/editline]

Right, so I thought that the problem maybe that i have


include('cl_init.lua')

in my init.lua file, so I removed it, but now it won’t add the command to bring the menu up.

AddCSLuaFile() it in init.lua

Err, just in case you understand why -TB- told you to put concommand.Add() on serverside is because:
concommand.Add() is a shared function, so you can put it in cl_init.lua BUT ONLY if you put clientside code in it, same with putting concommand.Add() on serverside, it must include serverside code.

Also, let me explain include() and AddCSLuaFile()
init.lua is automatically loaded(unless there are some really big errors like not including an ‘end’ or something that might completely break the gamemode, making it resort to sandbox)
Garrysmod looks if you have included files into the gamemode, both clientside and serverside.
Serverside files are added with include()
Clientside files are added with AddCSLuaFile()
Shared files are added by using both include() and AddCSLuaFile() on the file you wish to be shared