Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to Hide Button Gui for Players on a Certain Team?

I am trying to make a spectate GUI for my PvP game, and I need to make sure people currently in the game cannot access the spectator mode. Spectating is activated by a button to the side, so I am trying to make that button invisible to players within the game. All players within the game are put on the "In Game" team. The entire spectate GUI, including the button that activates it, are stored in a Gui that is stored in the StarterGui. This is a local script within the button:

local tp = game.Teams:FindFirstChild('In Game'):GetPlayers()
while wait() do 
	if #tp > 0 then
		script.Parent.Visible = false
	else
		script.Parent.Visible = true
	end
end

I'm not entirely sure if I am doing this correctly at all, I'm kind of just grasping at straws, but that script doesn't make it invisible to players in the game. Anyone know how I could properly do this?

1 answer

There is such a way to do this, and it's by checking the player's team. I'll explain how to do so.

An Example

Let's say that you made a red and a blue team, and you want to hide that same Gui Button in there for the red team to see only, you would need to do an if function, the if function would check the game to see if the player's team is red or another color (blue, green, pink, baby blue, you name it) and if the team is true, then the function will perform, and if not, then the function would be terminated for that certain other team. Here's what the code would look like

Code

local Player = game.Players.LocalPlayer--Doing this since I'm too lazy when it comes to coding
local TB = game.StarterGui.ScreenGui.TextButton--Easiest thing I can think of

TB.Visible = false--Make it false by default so that way you can make it invisible for the other team.

if game.Player.TeamColor == BrickColor.new('Really Red') then--Checks if your team is the color Really Red
         TB.Visible = true--makes the TB visible for the team
end

More Explaining...

So the if function can pretty much be used to see if something is true or false, it can check whether the player is wearing a certain item, doing a certain movement, etc. Also, explaining the code, you could make the ScreenGui visible = false so that way none of the teams can see it unless the player is already on that team, in which case the Gui will be visible for the player and their teammates only. Hope I explained it good enough, and based off this example you should know where to plug this into your code, see ya.

Greek

This discussion is preserved as it was. New answers, comments, and votes are closed.