MyBB registration error

Lua Error: Hook [addons\mybb\lua\autorun\cl_mybb.lua:4] attempt to call global ‘LocalPlayer’ (a nil value)

I don’t know how to fixed i try a lot of but i give up.

cl_mybb.lua



print("This server is running MyBB Registeration by Clark(Aide)")

concommand.Add("mybb_register", function( )
	local p = LocalPlayer()
	DFrame1 = vgui.Create("DFrame")
	DFrame1:SetSize(186, 224)
	DFrame1:SetPos(ScrW() / 2 - 63, ScrH() / 2 - 112)
	DFrame1:SetTitle("Account Creation")
	DFrame1:SetSizable(true)
	DFrame1:SetDeleteOnClose(false)
	DFrame1:ShowCloseButton(false)
	DFrame1:MakePopup()
	DFrame1.Paint = function()
		draw.RoundedBox( 6, 0, 0, 186, 224, Color( 29, 36, 53, 255 ) )
	end
	
	local DImage9 = vgui.Create("DImageButton", DFrame1)
	DImage9:SetSize(16, 16)
	DImage9:SetPos(164, 4)
	DImage9:SetImage( "gui/silkicons/folder_go" )
	DImage9:SetToolTip( "Already have an account?" )
	DImage9:SizeToContents()
	DImage9.DoClick = function()
		RunConsoleCommand("mybb_link")
		DFrame1:Close()
	end
	
	// Username
	local DLabel1 = vgui.Create("DLabel", DFrame1)
	DLabel1:SetPos(10, 30)
	DLabel1:SetText("Username")
	DLabel1:SizeToContents()

	local DTextEntry1 = vgui.Create("DTextEntry", DFrame1)
	DTextEntry1:SetSize(125, 20)
	DTextEntry1:SetPos(30, 44)
	DTextEntry1:SetText("")
	DTextEntry1.Think = function( )
		local username = DTextEntry1:GetValue()
		if string.len(username) > 5 then
			DImage5:SetImage( "gui/silkicons/check_on" )			
		end
	end
	
	local DImage1 = vgui.Create("DImage", DFrame1)
	DImage1:SetSize(16, 16)
	DImage1:SetPos(10, 44)
	DImage1:SetImage("gui/silkicons/user")
	DImage1:SizeToContents()
	
	DImage5 = vgui.Create("DImage", DFrame1)
	DImage5:SetSize(16, 16)
	DImage5:SetPos(160, 44)
	DImage5:SetImage( "gui/silkicons/check_off" )
	DImage5:SizeToContents()
	
	// Password
	local DLabel2 = vgui.Create("DLabel", DFrame1)
	DLabel2:SetPos(10, 68)
	DLabel2:SetText("Password")
	DLabel2:SizeToContents()

	local DTextEntry2 = vgui.Create("DTextEntry", DFrame1)
	DTextEntry2:SetSize(125, 20)
	DTextEntry2:SetPos(30, 83)
	DTextEntry2:SetText("")
	DTextEntry2.Think = function( )
		local password = DTextEntry2:GetValue()
		if string.len(password) > 5 then
			DImage6:SetImage( "gui/silkicons/check_on" )
		end
	end

	local DImage2 = vgui.Create("DImage", DFrame1)
	DImage2:SetSize(16, 16)
	DImage2:SetPos(10, 83)
	DImage2:SetImage("gui/silkicons/shield")
	DImage2:SizeToContents()

	DImage6 = vgui.Create("DImage", DFrame1)
	DImage6:SetSize(16, 16)
	DImage6:SetPos(160, 83)
	DImage6:SetImage( "gui/silkicons/check_off" )
	DImage6:SizeToContents()
	
	// Email
	local DLabel3 = vgui.Create("DLabel", DFrame1)
	DLabel3:SetPos(10, 110)
	DLabel3:SetText("Email")
	DLabel3:SizeToContents()

	local DTextEntry3 = vgui.Create("DTextEntry", DFrame1)
	DTextEntry3:SetSize(125, 20)
	DTextEntry3:SetPos(30, 125)
	DTextEntry3:SetText("")
	DTextEntry3.Think = function( )
		local email = DTextEntry3:GetValue()
		if string.len(email) > 8 then
			DImage7:SetImage( "gui/silkicons/check_on" )
		end
	end

	local DImage3 = vgui.Create("DImage", DFrame1)
	DImage3:SetSize(16, 16)
	DImage3:SetPos(10, 125)
	DImage3:SetImage("gui/silkicons/world")
	DImage3:SizeToContents()
	
	DImage7 = vgui.Create("DImage", DFrame1)
	DImage7:SetSize(16, 16)
	DImage7:SetPos(160, 127)
	DImage7:SetImage( "gui/silkicons/check_off" )
	DImage7:SizeToContents()

	// Submit
	local DButton1 = vgui.Create("DButton", DFrame1)
	DButton1:SetSize(70, 25)
	DButton1:SetPos(58, 194)
	DButton1:SetText("Submit")
	DButton1.Paint = function()
		draw.RoundedBox( 6, 0, 0, 70, 25, Color( 32, 40, 57, 255 ) )
	end
	
	DButton1.DoClick = function()
		local username = DTextEntry1:GetValue()
		local password = DTextEntry2:GetValue()
		local email = DTextEntry3:GetValue()
		if string.len(username) < 6 then LocalPlayer():ChatPrint("[MyBB] Your username has be 6 characters or more.") return end
		if string.len(password) < 6 then LocalPlayer():ChatPrint("[MyBB] Your password has be 6 characters or more.") return end
		if string.len(email) < 8 then LocalPlayer():ChatPrint("[MyBB] Your email has be 8 characters or more.") return end
		DFrame1:Close()
		datastream.StreamToServer( "SendInfo", { username, password, email } )
	end
end)

concommand.Add("mybb_link", function( )
	local p = LocalPlayer()
	DDFrame1 = vgui.Create("DFrame")
	DDFrame1:SetSize(186, 224)
	DDFrame1:SetPos(ScrW() / 2 - 63, ScrH() / 2 - 112)
	DDFrame1:SetTitle("Account Link")
	DDFrame1:SetSizable(true)
	DDFrame1:SetDeleteOnClose(false)
	DDFrame1:ShowCloseButton(false)
	DDFrame1:MakePopup()
	DDFrame1.Paint = function()
		draw.RoundedBox( 6, 0, 0, 186, 224, Color( 29, 36, 53, 255 ) )
	end
	
	local DImage9 = vgui.Create("DImageButton", DDFrame1)
	DImage9:SetSize(16, 16)
	DImage9:SetPos(164, 4)
	DImage9:SetImage( "gui/silkicons/folder_go" )
	DImage9:SetToolTip( "Don't have an account?" )
	DImage9:SizeToContents()
	DImage9.DoClick = function()
		RunConsoleCommand("mybb_register")
		DDFrame1:Close()
	end
	
	// Username
	local DDLabel1 = vgui.Create("DLabel", DDFrame1)
	DDLabel1:SetPos(10, 30)
	DDLabel1:SetText("Username")
	DDLabel1:SizeToContents()

	local DDTextEntry1 = vgui.Create("DTextEntry", DDFrame1)
	DDTextEntry1:SetSize(125, 20)
	DDTextEntry1:SetPos(30, 44)
	DDTextEntry1:SetText("")
	DDTextEntry1.Think = function( )
		local username = DDTextEntry1:GetValue()
		if string.len(username) > 3 then
			DDImage5:SetImage( "gui/silkicons/check_on" )			
		end
	end
	
	local DDImage1 = vgui.Create("DImage", DDFrame1)
	DDImage1:SetSize(16, 16)
	DDImage1:SetPos(10, 44)
	DDImage1:SetImage("gui/silkicons/user")
	DDImage1:SizeToContents()
	
	DDImage5 = vgui.Create("DImage", DDFrame1)
	DDImage5:SetSize(16, 16)
	DDImage5:SetPos(160, 44)
	DDImage5:SetImage( "gui/silkicons/check_off" )
	DDImage5:SizeToContents()
	
	// Password
	local DDLabel2 = vgui.Create("DLabel", DDFrame1)
	DDLabel2:SetPos(10, 68)
	DDLabel2:SetText("Password")
	DDLabel2:SizeToContents()

	local DDTextEntry2 = vgui.Create("DTextEntry", DDFrame1)
	DDTextEntry2:SetSize(125, 20)
	DDTextEntry2:SetPos(30, 83)
	DDTextEntry2:SetText("")
	DDTextEntry2.Think = function( )
		local password = DDTextEntry2:GetValue()
		if string.len(password) > 3 then
			DDImage6:SetImage( "gui/silkicons/check_on" )
		end
	end

	local DDImage2 = vgui.Create("DImage", DDFrame1)
	DDImage2:SetSize(16, 16)
	DDImage2:SetPos(10, 83)
	DDImage2:SetImage("gui/silkicons/shield")
	DDImage2:SizeToContents()

	DDImage6 = vgui.Create("DImage", DDFrame1)
	DDImage6:SetSize(16, 16)
	DDImage6:SetPos(160, 83)
	DDImage6:SetImage( "gui/silkicons/check_off" )
	DDImage6:SizeToContents()
	
	// Submit
	local DDButton1 = vgui.Create("DButton", DDFrame1)
	DDButton1:SetSize(70, 25)
	DDButton1:SetPos(58, 194)
	DDButton1:SetText("Submit")
	DDButton1.Paint = function()
		draw.RoundedBox( 6, 0, 0, 70, 25, Color( 32, 40, 57, 255 ) )
	end
	
	DDButton1.DoClick = function()
		local username = DDTextEntry1:GetValue()
		local password = DDTextEntry2:GetValue()
		if string.len(username) < 4 then LocalPlayer():ChatPrint("[MyBB] Your username has be 4 characters or more.") return end
		if string.len(password) < 4 then LocalPlayer():ChatPrint("[MyBB] Your password has be 4 characters or more.") return end
		DDFrame1:Close()
		datastream.StreamToServer( "CheckMatch", { username, password } )
	end
end)


sv_mybb.lua



require("tmysql")
require("cryptopp")

Host = "localhost" // Host(IP/Hostname)
User = "gmodas" // Username
Pass = "wsWtcvs5U3rUxWXn" // Password
DB = "smf" // Databse to select
Port = 3306 // Port, By default it's 3306.
Group = 2 // This is the default group they will be placed into. By default 0 is registered. Must be a number!
WEBURL = "http://www.garrysmod.com" // This is your website url.

tmysql.initialize( Host, User, Pass, DB, Port )

local Player = _R.Player

function SQLHandle( result, _, error )
	if error and error != 0 then
		print( "SQL ERROR: " .. error )
	end
end

// This creates a user as if he/she was registering on the forums.
function Player:RegisterUser( uid, user, pass, email, group, regdate )
	if !user or !pass or !email then self:ChatPrint( "[MyBB] Failed to create new user, one of the fields were nil." ) return end
	if !group then group = Group or 2 end
	if !uid then uid = self:SteamID() end
	if !regdate then regdate = os.time() end
	print("Registered, " .. user .. ".")
	tmysql.query("INSERT INTO `mybb_users` (`username`, `password`, `email`, `usergroup`, `allownotices`, `hideemail`, `invisible`, `receivepms`, `showsigs`, `showavatars`, `showquickreply`, `regdate`, `regip`, `lastip`, `steamid`) VALUES ('" .. tmysql.escape(user) .. "', '" .. tmysql.escape(string.lower(crypto.md5(pass))) .. "','" .. tmysql.escape(email) .. "', '".. group .. "', '" .. 1 .. "', '" .. 0 .. "', '" .. 0 .. "', '" .. 1 .. "', '" .. 1 .. "', '" .. 1 .. "', '" .. 1 .. "', '" .. regdate .. "', '" .. self:IPAddress() .. "', '" .. self:IPAddress() .. "', '" .. tmysql.escape(self:SteamID()) .. "' )" , SQLHandle )
	self:ChatPrint( "[MyBB] Successfully registered user, " .. user )
	self.Register = true
end

// This is to check to see if our password we imputed matches the password stored in mysql database.
function _R.Player:LinkUser( u, a )
	print( u, a )
	local Password, Salt
	if self:GetUsersID( self:SteamID() ) then self:ChatPrint( "[MyBB] Your account is/was already linked." ) end
	tmysql.query( "SELECT `password`, `salt` FROM `mybb_users` WHERE `username`= '" .. u .. "'", function ( Args )
		if Args[1] then
			Password = Args[1][1]
			Salt = Args[1][2]
		else
			RunConsoleCommand("mybb_register")
			self:ChatPrint( "[MyBB] User doesn't exist." )
		end
		a = string.lower(tostring(a))
		a = string.lower(crypto.md5(Salt) .. crypto.md5(a))
		a = string.lower(crypto.md5(a))
		if a == Password then
			tmysql.query("UPDATE `mybb_users` SET `steamid`='" .. tmysql.escape(self:SteamID()) .. "' WHERE `username`='" .. u .. "'", SQLHandle )
			self:ChatPrint( "[MyBB] Successfully linked forum account." )
		else
			RunConsoleCommand("mybb_link")
			self:ChatPrint( "[MyBB] The password you supplied didn't match the one supplied by the forum." )
		end
	end)
end

// We can use this for a custom admin mod. Or use this to set admins. You could have your admins be controled via the forums.
function Player:GetUsersGroup( id )
	if !id then self:ChatPrint( "[MyBB] Failed to get user, got a nil value in argument." ) return end
	tmysql.query( "SELECT `usergroup` FROM `mybb_users` WHERE `steamid`= '" .. id .. "'", function ( Args )
		if (Args && Args[1]) then
			self:ChatPrint( "[MyBB] User is a part of group number " .. Args[1] )
		else
			self:ChatPrint( "[MyBB] Failed to get user's group." )
		end
	end)
end

// We use this to see if he/she is registered.
function Player:GetUsersID( id )
	if !id then self:ChatPrint( "[MyBB] Failed to get user, got a nil value in argument." ) return end
	tmysql.query( "SELECT `steamid`, `password`, `salt` FROM `mybb_users` WHERE `steamid`= '" .. id .. "'", function ( Args )
		if Args[1] then
			self.Register = true
			self:ChatPrint( "[MyBB] Welcome back " .. self:Nick() .. ", Remember to visit our forums @ " .. WEBURL )
		else
			self.Register = false
			self:ChatPrint( "[MyBB] Hello " .. self:Nick() .. ", starting registration process."  )
			RunConsoleCommand("mybb_register")
		end
	end)
end

hook.Add("PlayerInitialSpawn", "FirstSpawn", function( pl )
	pl.Register = false
	pl:GetUsersID( pl:SteamID() )
end)

datastream.Hook("SendInfo", function( p, h, i, e, d )
	if !d[1] or !d[2] or !d[3] then return end
	LocalPlayer():RegisterUser( LocalPlayer():SteamID(), d[1], d[2], d[3] )
	timer.Simple( 5, function( )
		LocalPlayer():GetUsersID( d[1] )
	end)
end)

datastream.Hook("CheckMatch", function( p, h, i, e, d )
	if !d[1] or !d[2] then return end
	LocalPlayer():LinkUser( d[1], d[2] )
end)


cl_ means it’s a client side file, looks like you’re running it server side

Place the cl file in autorun/client and see if that works.

now i’m getting error unknown command “mybb_register”