Making a spectating team

Hey !
I’m making a spectating team, and I want that ONLY the spectating team can see a specific gui, here is the code :

local Player = game:GetService("Players")
local Team = game:GetService("Teams")

while true do
game.Players.PlayerAdded:Connect(function(player)
	if player.Team == Team.Spectating then 
		script.Parent.Parent.Parent.Visible = true
		end
	end)
end

why is game.Players.PlayerAdded not game.Player.PlayerAdded?

1 Like

Hi! I see, your code is a little bit incorrect. Here would be a fix of it:

local Team = game:GetService("Teams")
local UI = script.Parent.Parent.Parent

game.Players.PlayerAdded:Connect(function(player)
if player.Team == Team["Spectating"] then
UI.Visible = true
   end
 end)
end

Don’t tell me that my mistake is that stupid…

That would not work. It’s would be Player.PlayerAdded, but I make it in my code above to fix it.

My code is the right one, @Black_Albi, you can test it if you want.

I’m animating something rn ^^
Thanks for you script, Imma save my anim and try it :slight_smile:

no it’s not, it’s just you can do it like that, just you don’t need to call the player service, you already did in the playeradded.

Your code literally doesn’t do anything. Not only is script mispelled as scrupt, but also Team["Spectating"] is the same as Team.Spectating

There is no need for the while loop.

Well. First, I removed the while, I fixed scrupt.

scrupt is an error of copy cuz I had an image on my clip board and I didn’t want to lose it (I’m wondering why I didn’t paste it on paint…)

Script doesn’t work

  • 676472 -

It is supposed to work. Can you show us the output so we can see the errors?

Maybe make a while true do
– zdadzdad

this on a localscript? this is probably the issue.

Yes it is
– DOn’t mind this –

alright i just got done with some stuff, let me review this, should take less than a few minutes unless i forget how to use teams.

i have somehow located the issue, im looking into it further.

“player.Team == Team.Spectating” shouldn’t be like this, it doesn’t print anything out so i’ll check on what i can do.

Normally you can do Team[“Spectating”]

doesn’t work either, i’ve gotten off track but i am looking for other ways to pull this off.