Players Not Being Moved to Spectator

I’m trying to get these functions to work:

function GM:PlayerInitialSpawn(target_ply)
target_ply:SetTeam( TEAM_GUARD_DEAD )
target_ply:SetTeam( TEAM_PRISONER_DEAD )
GAMEMODE:PlayerSpawnAsSpectator( player)
end

Players still spawn in the middle of the round.This gives me the error

gamemodes/base/gamemode/player.lua:227: attempt to call method ‘StripWeapons’ <a nil value>

  1. PlayerSpawnAsSpectator - gamemodes/base/gamemode/player.lua:227
  2. unknown - gamemodes/jailbreak/gamemode/init.lua:37

function GM:PlayerDeath(ply)
if ply:Team(TEAM_GUARD) then
ply:SetTeam(TEAM_GUARD_DEAD) elseif
ply:Team(TEAM_PRISONER) then
ply:SetTeam(TEAM_PRISONER_DEAD)
end
GAMEMODE:PlayerSpawnAsSpectator( player )
end

This gives me no error, but when the player dies the game auto respawns them. Neither move the player to spectate.

Welcome to Facepunch, please wrap code with


 tags.

PlayerInitialSpawn is called slightly before the player object is valid for certain functions; so stripping weapons wouldn't do any good.

Here's an example of everything you need to set up "spectators" so that on join, by default, the player joins as a spectator: https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/spectating_players_system.lua.html

There is no need to Set the team twice on initial spawn; set it once and don't strip on initial.

you are using Chessnuts jailbreak gamemode, which you have probably leaked.

Anywho, I im pretty sure, correct me if im wrong, but the strip weapons has nothing to do with this ulx script?

Try something like this



hook.Add("PlayerInitialSpawn", "Swaggy", function()
      timer.Simple(5, function() --Wait till the player actully spawns. remove it if you want.
            ply:KillSilent()
            ply:SetTeam(TEAM_PRISONER_DEAD)
      end)
end)


place it autorun/server