Unspectate not working as expected

I’ve been working on a spectate and the unspectate is causing all sorts of headaches for me. Everything I’ve tried will leave the player invisible and only show their weapons. I’ve looked at other spectate scripts and it seems that they either do just UnSpectate(), just Spawn() or a combination of both, which I’ve tried. Here’s my code with comments outlining what I’ve done

local function StopSpectate(ply)
if CLIENT then return end
ply:Spawn() – I’ve tried just this and I’ve tried leaving it out. I’ve also tried moving this after UnSpectate()
ply:UnSpectate() – I’ve tried just this and I’ve tried leaving it out
– I tried doing Spectate(OBS_MODE_NONE) as well.
– I tried KillSilent() as well since suiciding manually makes the player visible again. KillSilent did not make them visible.
ply:SetPos(ply.BS_Spectate.pos) – Return player back to the position prior to spectate
ply:SetHealth(ply.BS_Spectate.health) – Set players health back to how it was prior to spectate


One thing that is confusing me. If I run UnSpectate() on the player in command line on the server it will keep the player invisible. Then if I run Spawn() on them, they will become visible. So to me, it seems to be some issue with the commands running one right after the other, but unsure why that’d be the case.

Spawn the player after you unspectate him.