Help with this small script

[lua]if SERVER then

AddCSLuaFile ("clcon.lua")

end

function FirstSpawn( ply )

local client = LocalPlayer()
    if ( client:IsValid ) then
        RunConsoleCommand("cl_showfps", "2")
            else
                Error("Looks like you are not a valid player, oh noes!")

end

local cl = GetConVarNumber ( "cl_showfps" )
    if cl != 2 then
        Error("FailPalm")
            else
                Msg("WOOT!")

end

hook.Add( “PlayerInitialSpawn”, “playerInitialSpawn”, FirstSpawn )[/lua]

I’m not getting any errors, and it is not working, so why won’t my script run? its in orangebox/garrysmod/lua/autorun/client, I also tried it in autorun/server, this is a dedicated server by the way.

PlayerInitialSpawn is a server-side hook.

Also



**orangebox**/garrysmod/lua/autorun/client


Wat?

You’re also missing an end…

It’s a dedicated server.

I said I also tried it in autorun/server.

Also as I said, its a dedicated server, so rather then garrysmod/garrysmod, its whateveryouwant/orangebox/garrysmod.

It would be helpful to know where I am missing an end.

Above hook.Add

Thanks, there were 2 errors which popped up, fixed them both, but LocalPlayer is nil, so the hook gets removed, I tried InitPostEntity, but either I’m doing it wrong, or it won’t work for what I want it to do, this is the current code:

[lua]if SERVER then

AddCSLuaFile ("clcon.lua")

end

function FirstSpawn( ply )

local ply = LocalPlayer()
    if ply:IsValid() then
        RunConsoleCommand("cl_showfps", "2")
            else
                Error("Looks like you are not a valid player, oh noes!")

end

local cl = GetConVarNumber ( "cl_showfps" )
    if cl != 2 then
        Error("FailPalm")
            else
                Msg("WOOT!")

end
end
hook.Add( “PlayerInitialSpawn”, “playerInitialSpawn”, FirstSpawn )[/lua]

EDIT: so, I got rid of localplayer, and it ran, but the console command was not recognized, most likely due to the fact “Console” is not a player, so later I’ll experiment with user messages, and hope it works.

**[Player.ConCommand

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

It would benefit you to read up about proper tabbing practise. It would make missing ends and such easier for you to locate.

[lua]if SERVER then
AddCSLuaFile (“clcon.lua”)
end

function FirstSpawn( ply )
local ply = LocalPlayer()
if ply:IsValid() then
–RunConsoleCommand(“cl_showfps”, “2”)
– that would run the command on the server.
ply:ConCommand(“cl_showfps 2”)
else
Error(“Looks like you are not a valid player, oh noes!”)
end

--local cl = GetConVarNumber ( "cl_showfps" )
local cl = ply:GetInfo("cl_showfps") -- This might not work.
if cl != 2 then
	Error("FailPalm")
else
	Msg("WOOT!")

end

end
hook.Add( “PlayerInitialSpawn”, “playerInitialSpawn”, FirstSpawn )[/lua]

RunConsoleCommand will run the command on the server if you run it on the server, and on the client if you run it on the client.