ply:SetModel for team | Tables | Help

Hey there.

Im currently coding a gamemode, and I have some troubles. I posted a few topics already, and still dont figure out 100% how to finsih off my team code.

So, basically, I set up a table with functions inside the player.lua folder.

local ply = FindMetaTable( "Player" )

local teams = {}

teams[1] = {name = "Enforcer", color = Vector( 0.0, 0.0, 0.0 ), weapons = {"weapon_crowbar", "weapon_pistol", "weapon_physcannon", "weapon_physgun","gmod_camera", "gmod_tool"} }
teams[2] = {name = "Bomb Planter", color = Vector( 0.0, 0.0, 0.0 ), weapons = {"weapon_crowbar", "weapon_pistol", "weapon_physcannon", "weapon_physgun","gmod_camera", "gmod_tool"} }

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

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

and set up the actual teams in the shared.lua:

team.SetUp( 1, "Enforcer", Color(0, 0, 255) )
team.SetUp( 2, "Bomb Planter", Color(255, 0, 0) )

Then I made a DFrame with DButtons to change to a certain team:

local button = vgui.Create( 'DButton' )
			button:SetParent( base )
			button:SetPos( ScrW()/25 + 160, ScrH()/25 + 80 )
			button:SetSize( 100, 20 )
			button:SetText( 'Bomb Planter' )
			function button:Paint( w, h )
				draw.RoundedBox( 0, 0, 0, w, h, Color(222, 222, 222, 120 ) )
			local In = false
			button.OnCursorEntered = function()
				In = true
				--surface.SetDrawColor(200, 220, 220, 255)
				--surface.DrawRect(0, 0, button:GetWide(), button:GetTall())
			button.OnCursorExited = function()
				In = false
			function button:Paint( w, h )
				if In then
				surface.SetDrawColor(222, 222, 222, 60 )
				surface.DrawRect(0, 0, button:GetWide(), button:GetTall())
			function button:DoClick()

and now Im a bit confused. Everything is working. When I type the consol command I set up to call the derma “pkgaming_menu” everything pops up, and when I select the team through the DButton DoClick function, I actually change team. BUT: I do not change my model, which is pretty stupid. I tried a LOT, seriously A LOT of functions: For example, I set up a new library “ChangeModel”, but didnt work. I set up a new table "models = {} models[1] = “/models…” and stuff like that, and tried to call it back. I never had errors or anything like that, but It never changed my model to the team I have.

Please help me with this, It would make me be 100 times happier. -.- I try to end this section of my gamemode now since some days, but always get stuck at the easiest parts.

Thanks so much (again) for helping me. I really appreciate your help!


If you need any additional script, file, etc. please feel free to contact me on this forum.

Why didn’t you show us the code where you change the model instead of showing us irrevelant stuff?

Yes, im pretty dumb haha I must admit. Whatever!

I figured it out eventually!

I had to create a function that reffers to the table I made with the teams

Thanks anyways!