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```
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.
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.
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)
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.