Disabling third person on death

My script uses ls_thirdperson 1 and ls_thirdperson 0 to change camera angles whenever /thirdperson and /firstperson are typed into chat. If a player dies in third person they get a glitchy spectate screen.

I’m trying to make ls_thirdperson set to 0 when a player dies. Here is my attempt, I can’t really test it now, but am I close?


function GM:DoPlayerDeath( ply, attacker, dmginfo )

if ( Player:IsValid() ) then
		Player:ConCommand( "ls_thirdperson 0" )
		end
	end

1st, don’t overwrite gamemode functions, unless you’re making your own gamemode. Use hooks instead.
2nd, your passing the ply argument in your function, but you’re indexing Player, which hasn’t been defined.
Try this instead.



hook.Add("DoPlayerDeath", "ChangeToFirstperson", function(ply, attacker, dmginfo)
	if ply:IsValid() then --Is the player valid? If so, continue.
		ply:ConCommand("ls_thirdperson 0") --Set the players view to first.
	end
end)