Hide a gui on certain team, reappear when changed

I want this script to hide a certain ScreenGUI that is set to be enabled automatically, then I want when your on Inmate team for it to hide, and when the team changes it’ll reappear. I cannot use Destroy() as then I can’t make it reappear.

This is a ServerScript inside workspace!

local player = game.Players.LocalPlayer
local teams = game:GetService("Teams")
wait()
if player.Team == teams["Inmate"] then
	player.PlayerGui:WaitForChild("TeamSwitchGui").Enabled = false
elseif player.Team ~= teams["Inmate"] then
	player.PlayerGui:WaitForChild("TeamSwitchGui").Enabled = true
end```
1 Like
player:GetPropertyChangedSignal("Team"):Connect(function()
	if player.Team == teams["Inmate"] then
		player.PlayerGui:WaitForChild("TeamSwitchGui").Enabled = false
	elseif player.Team ~= teams["Inmate"] then
		player.PlayerGui:WaitForChild("TeamSwitchGui").Enabled = true
	end
end)

This’ll run that block of code whenever you change team.

1 Like

Okay, I’m testing now. I’ll let you know if it works!


One second, roblox now broke for me before I ran the game. Let me try to fix this :confused:

Nothing seemed to change with my script and yours.
I didn’t see any difference whatsoever, on that team the GUI was still there.

Is the script suppose to be a ServerScript in Workspace?

It should be in a local script. Everything inside the “player:GetPropertyChangedSignal(“Team”)” will run every time the team property is changed.
Edit: Make sure your code is running properly by putting prints in it.

Are you trying it so if a player joins a team i’ll give them the gui or not?

local player = game.Players.LocalPlayer
local teams = game:GetService("Teams")
wait()
player:GetPropertyChangedSignal("Team"):Connect(function()
	print("Player Team Change Detected")
	if player.Team == teams["Inmate"] then
		player.PlayerGui:WaitForChild("TeamSwitchGui").Enabled = false
		print("Player is on Inmate")
	elseif player.Team ~= teams["Inmate"] then
		player.PlayerGui:WaitForChild("TeamSwitchGui").Enabled = true
		print("Player is on another team")
	end
end)

I got none of my prints back.

The reason I got no prints possibly is because it’s in workspace?

Get rid of the wait(), put a print at the start of your script. If that print doesn’t run then your script isn’t running and that’s an issue with where you put it.

Local scripts don’t run in workspace. They run in your character, your UI, your player scripts and in replicatedfirst.

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