How to disable a GUI when a player is changed to a specific team

I am trying to make it so when a players team is changed to the jail team, a certain GUI is disabled for them. I have a team change GUI that I want to be disabled as soon as the person is switched to the jailed team to avoid them changing teams to evade being arrested. I have tried many ways of doing this and none work, can someone help me out?

Could you please show your code, so we as community can see what’s wrong with it?

I haven’t found a way of doing it so when the players team is changed it executes the script. I have the code to change the team, but it doesn’t have code to execute it.

local Player = game.Players.LocalPlayer
local TB = game.Players.LocalPlayer.PlayerGui.teamChanger

TB.Visible = true
if game.Player.TeamColor == BrickColor.new(‘Burnt Sienna’) then
TB.Visible = false
end

You should use Player:GetPropertyChangedSignal() to detect when the team color is changed.

So if you have something like this.

image

You can simply write this into your LocalScript.

local function updateGUI() -- we will call this function to update the gui based off the team the player is in
	local team = game.Players.LocalPlayer.Team -- create variable so we dont have to repeat this
	for _, screen in pairs(script.Parent:GetChildren()) do -- go over all screenguis that we have
		if screen:IsA("ScreenGui") then -- check if the instance we went over is a screengui
			screen.Enabled = (screen.Name == team.Name) -- set the enabled state based off the team name
			-- so if player is in the blue team; we will enable the gui for blue team
			-- otherwise we gonna set the enabled to false, so player cant see other team guis
		end
	end
end
game.Players.LocalPlayer.Team.Changed:Connect(updateGUI) -- listen for team change
updateGUI() -- call the function, since we this localscript just got executed

I hope it helped :happy1:.

That fixed it, thank you for your help!

1 Like