[Need Help] Gmod Lua Need Help

Hey im MrCoby220 and i am working on a new Gmod gamemode and i searched on wiki.garrysmod.com how to do a team spawn but i tried some of the exemple and its never work if you need more info:

Team name: 0 = Counter Terrorist(Blue) 1 = Terrorist(Red)
Map: gm_construct (i will change it)
Gamemode name: Gmod Go
Max player: 16
Can respawn: Yes but not after whe died

(Sorry for this shity english)

i hope some one can help me thanks if you can :slight_smile:

my custom teams spawnpoint code


local teams = {}

teams[0].spawnpoint[1] = Vector(1635.777710,-1943.107056,-79.968750)
teams[0].spawnpoint[2] = Vector(1616.266235,-1173.823853,-79.968750)
teams[0].spawnpoint[3] = Vector(1245.563721,-1110.635254,-79.968750)

teams[1].spawnpoint[1] = Vector(-4528.927734,4827.819336,-31.968750)
teams[1].spawnpoint[2] = Vector(-4911.646484,5239.514648,-31.968750)
teams[1].spawnpoint[3] = Vector(-4597.583496,5890.459473,-31.968750)

ply:SetPos(table.Random(teams[0]))

ply:SetPos(table.Random(teams[1]))

and i got this error

[ERROR] gamemodes/gmodgo/gamemode/teams/sh_teams.lua:8: attempt to index field ‘spawnpoint’ (a nil value)

What code do you have

The code is now on the post. “UP”

It’s because you never initialized the spawnpoint index as a table before trying to insert data.

teams.spawnpoint = { };

ok i will see if it work if is thanks :wink:

is not realy working or i just dont understend what you try to say to me :S

You have to initialize the spawnpoints table as Acecool said with


teams.spawnpoint = {}

Also, when the player dies make him spawn with


ply:spawn()

because setting a dead’s position is useless.

[lua]
Player:Spawn()
[/lua]

Lua is case sensitive.

where did the teams.spawnpoint = {} go ? and i did what you said im just spawning where i died