What can i change code to to make player "unspectate"

Okay so i have a spectate command for my gmod gamemode:

–Spectate
function chatCommand( ply, text, public )
if (string.sub(text, 1) == “!spectate_game”) then
ply:Spectate( 6 )
return(false)
end
end
hook.Add( “PlayerSay”, “chatCommand”, chatCommand );

And im trying to make a join game command here is what i have:

–Join game

function chatcommand( ply, text, public )
if (string.sub(text, 1) == “!join_game”) then
ply:Spectate( 6 ) --what do i replace this with to unspectate
return(false)
end
end
hook.Add( “PlayerSay”, “chatcommand”, chatcommand );

thanks any help is appricieted

Player:UnSpectate
Maybe you could try Googling it next time? It was literally the first result simply by typing in “unspectate”…



function chatcommand( ply, text, public )
if (string.sub(text, 1,10) == "!join_game") then -- Fixed your substring
ply:UnSpectate() -- replaced
return(false)
end
end
hook.Add( "PlayerSay", "chatcommand", chatcommand );



thanks bro appriciet it