Disable gui while on Jailed team

Hello smart people of the devforum, I suck at scripting and I need your help.

I have a gui that I want to disable when someone is on the “Jailed” team.
image

I have tried time and time again to try to find a simple solution but it just doesn’t work maybe because I am doing things wrong.

Below is the most recent fail I did. (send help)

local Player = game:GetService("Players").LocalPlayer
local Team = game:GetService("Teams")["Jailed"]

if Player.Team == Team then
	game.StarterGui.MainGUI.Control_Buttons.Visible = false
end

The way to do this would be using Player:GetPropertyChangedSignal(“Team”).

Example:

local Team = game:GetService(“Teams”)[“Jailed”]

game.Players.PlayerAdded:Connect(function(Player)
Player:GetPropertyChangedSignal(“Team”):Connect(function()
if Player.Team == Team then
game.StarterGui.MainGUI.Control_Buttons.Visible = false
end
end)
end)

@4667hp has a better code. Use that instead of mine, since mine had a mistake as well.

This should work.

		local Player = game:GetService("Players").LocalPlayer
	local Team = game:GetService("Teams")["Jailed"]

	local function CheckTeam()
		if Player.TeamColor == Team.TeamColor then
			Player.PlayerGui.MainGUI.Control_Buttons.Visible = false
		else
			Player.PlayerGui.MainGUI.Control_Buttons.Visible = true
		end
	end

	CheckTeam()
	Player:GetPropertyChangedSignal("Team"):Connect(CheckTeam)

You need to use player.PlayerGui not game.StarterGui when changing stuff in ui.

2 Likes

Depending on how the GUI is initialised here, there’s a few approaches you could take.

If the GUI is initialised on every respawn, you can just check the team of the player to see if it equals Jailed then disable the GUI

You should create a constant reference to the GUI by the way, just a tip :slight_smile:

local Gui = script.Parent

if Player.Team == Team then
  Gui.Enabled = false
end

If the GUI is initialised once, you can bind a change event to the Team and then compare it

Player:GetPropertyChangedSignal("Team"):Connect(function()
  Gui.Enabled = (Player.Team ~= Team)
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.