Flashlight isn't working and this error keeps popping up.

Hey. I’m trying to make a gamemode so when me and my friends play horror maps on Gmod, you can’t use the physgun, the spawn menu, etc. Well, there are 2 problems:

  1. The flashlight, one of the most important things I need, isn’t working, and I don’t know how to enable it.

  2. This error keeps popping up in the console:



[ERROR] gamemodes/goobermode/gamemode/player.lua:5: attempt to index local 'teams' (a number value)
  1. unknown - gamemodes/goobermode/gamemode/player.lua:5
   2. include - [C]:-1
    3. unknown - gamemodes/goobermode/gamemode/init.lua:5


This is what it says at player.lua:5


teams[1] = {name = "Funny Force", color = Vector (  138, 43, 226 ), weapons = {"weapon_crowbar"} }

This is what it says at init.lua:5


include("player.lua")

Any help is appreciated. I’m extremely new at making gamemodes, so please go easy on me.

Do you have a “teams” table? Without seeing more of your code, I can only say you’ll need one of these:
[lua]teams = teams or {}
–or
teams = {}
–or
local teams = {}[/lua]

[lua]
teams[1] = {name = “Funny Force”, color = Vector ( 138, 43, 226 ), weapons = {“weapon_crowbar”} }
[/lua]
a terrible, inefficient and laggy way of using tables - use locals.

Oh wow. I put in parenthesis instead of braces on my teams table. Thanks for that. But now, there’s a new error.



[ERROR] gamemodes/goobermode/gamemode/player.lua:23: attempt to index a nil value
  1. GiveGamemodeWeapons - gamemodes/goobermode/gamemode/player.lua:23
   2. unknown - gamemodes/goobermode/gamemode/init.lua:21


How about I just post my player.lua and my init.lua? I have a feeling it’s all messed up.

Player.lua


local ply = FindMetaTable("Player")

local teams = {}

teams[1] = {name = "Funny Force", color = Vector (  138, 43, 226 ), weapons = {"weapon_crowbar"} }

function ply:SetGamemodeTeam( n )
	if not teams[n] then return end
	
	self:SetTeam( n )
	
	self:SetPlayetColor( teams[n].color )
	
	self:GiveGamemodeWeapons()
	
	return true
end

function ply:GiveGamemodeWeapons()
	local n = self:Team()
	self:StripWeapons()
	
	for k, wep in pairs(teams[n].weapons) do
		self:Give(wep)
	end
end

Init.lua


AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")

include("shared.lua")
include("player.lua")

function GM:PlayerConnect( name, ip )
	print("Player: ".. name .." has joine.")
end

function GM:PlayerInitialSpawn( ply )
	print("Player: ".. ply:Nick() .." has spawned.")
	
	ply:SetGamemodeTeam(0)
end

function GM:PlayerSpawn( ply )
	ply:SetPlayerColor( Vector(  138, 43, 226 ) )
	ply:SetModel("models/player/Group01/male_03.mdl")
	ply:Give("weapon_crowbar")
	ply:GiveGamemodeWeapons()
end

function GM:PlayerAuthed( ply, steamID, uniqueID )
	
end

So I just throw local in front of teams[1]?

no, local table = {value}, {value2}

Sorry, I’m afraid I’m not sure what you mean. What do I put inside the values? Do I put the name of the team and the weapons in there?

local teams = {
{name = “Funny Force”, color = Vector ( 138, 43, 226 ), weapons = “weapon_crowbar”
}

should work, never really used locals in that way before

Thanks man. It worked great, but now there are more errors.




[ERROR] gamemodes/goobermode/gamemode/init.lua:14: attempt to call method 'SetGamemodeTeam' (a nil value)
  1. unknown - gamemodes/goobermode/gamemode/init.lua:14


[ERROR] gamemodes/goobermode/gamemode/init.lua:21: attempt to call method 'GiveGamemodeWeapons' (a nil value)
  1. unknown - gamemodes/goobermode/gamemode/init.lua:21



Also, can you teach me how to disable noclip and enable flashlights? mp_flashlight 1 isn’t working and neither is sbox_noclip 0.

sbox_noclip 0 or

[lua]
function GM:PlayerNoClip(ply)
return false
end
[/lua]

and flashlights should work, i don’t know why it doesn’t. sorry

what is line 21 if you don’t mind?

This is the table containing line 21.



function GM:PlayerSpawn( ply )
	ply:SetPlayerColor( Vector(  138, 43, 226 ) )
	ply:SetModel("models/player/Group01/male_03.mdl")
	ply:Give("weapon_crowbar")
	ply:GiveGamemodeWeapons()
end


Also, I found this for the flashlight.



Player:AllowFlashlight


How would I go about putting this in the lua script? Which one do I put it in?

err… bump?

self:SetPlayetColor( teams[n].color )



function GM:PlayerSpawn( ply )
	ply:SetPlayerColor( Vector(  138, 43, 226 ) )
	ply:SetModel("models/player/Group01/male_03.mdl")
	ply:Give("weapon_crowbar")
	ply:GiveGamemodeWeapons()
        **ply:AllowFlashlight( true )**
end


I gotta admit this, my first instinct was to reply: “Buy fresh batteries!” Then higher brain function convinced me otherwise… But I wrote it anyway…