Spectator- ConCommand

I am attempting to edit phrostwave’s spectator script to only work for admins (Just for my server, not gonna re-upload or anything.)


 function Spectate(ply, ent)
	if ply:IsValid() then
		if ply:IsAdmin() then --Checks to see if they're a admin
			ply:ChatPrint("You are now spectating!") --Tells them they are spectating
			ply:StripWeapons() -- Strips they're weapons.
			ply:Spectate(6) --Noclip-like spectating
			for _,all in pairs(player.GetAll()) do --Get everyone
				all:ChatPrint( ply:Nick() .. " is now spectating.") --Tells everyone I'm spectating
		else
		    ply:ChatPrint("You are not allowed to use this command!") -- Tells them they are not alloed to use this command (Not a admin)
            end
		end
	end
end
concommand.Add("spectate",Spectate) --Adds a console command

function UnSpectate(ply)
	if ply:IsValid() then
		if ply:IsAdmin() then
			ply:ChatPrint("You have stopped spectating!")
			ply:UnSpectate() --Get out of spectator.
			GAMEMODE:PlayerLoadout(ply) --Give their weapons back.
			ply:ConCommand("+jump;wait;-jump") --Fixes a bug where they don't have to press they're spacebar.
			for _,all in pairs(player.GetAll()) do --Get everyone
				all:ChatPrint( ply:Nick() .. " is no longer spectating.") --Tells everyone I'm not spectating anymore.
		else
            ply:ChatPrint("You are not allowed to use this command!") -- Tells me I'm not allowed to use this command either.
			end
		end
	end
end
concommand.Add("unspectate",UnSpectate) --Adds a console command

I’ve merely replaced the line of code which checks if your in spectator mode or not with a ply:IsAdmin(), the concommand doesn’t seem to register anymore, and I get a error saying there should be a ‘end’ somewhere under line 7 (for_,all).

Please help ( I am a total newbie at this… )

Errors never lie. You have duplicate ends on lines 12 and 28.

E: Nevermind, misplaced. Swap lines 12/13 and 14, and lines 26/27 and 28.

I’m not exactly following. Are you asking me to swap 12 and 13 with 14? Or 12/13 and 14 with 26/27 and 28?


 function Spectate(ply, ent)
	if ply:IsValid() then
		if ply:IsAdmin() then --Checks to see if they're a admin
			ply:ChatPrint("You are now spectating!") --Tells them they are spectating
			ply:StripWeapons() -- Strips they're weapons.
			ply:Spectate(6) --Noclip-like spectating
			for _,all in pairs(player.GetAll()) do --Get everyone
				all:ChatPrint( ply:Nick() .. " is now spectating.") --Tells everyone I'm spectating
		        end
                else
		    ply:ChatPrint("You are not allowed to use this command!") -- Tells them they are not alloed to use this command (Not a admin)
                end
	end
end
concommand.Add("spectate",Spectate) --Adds a console command

function UnSpectate(ply)
	if ply:IsValid() then
		if ply:IsAdmin() then
			ply:ChatPrint("You have stopped spectating!")
			ply:UnSpectate() --Get out of spectator.
			GAMEMODE:PlayerLoadout(ply) --Give their weapons back.
			ply:ConCommand("+jump;wait;-jump") --Fixes a bug where they don't have to press they're spacebar.
			for _,all in pairs(player.GetAll()) do --Get everyone
				all:ChatPrint( ply:Nick() .. " is no longer spectating.") --Tells everyone I'm not spectating anymore.
		        end
               else
                    ply:ChatPrint("You are not allowed to use this command!") -- Tells me I'm not allowed to use this command either.
		end
	end
end
concommand.Add("unspectate",UnSpectate) --Adds a console command

Thanks, it works pretty well now.

[editline]12:20AM[/editline]

Also, I’ve noticed you can exit/enter noclip whilst in spectator mode, is there any way to temporarily block an alias? Something like block.Alias(“noclip”) or something like that?

Nvm, I got a friend to help.