Team GUI script not working

[This is a serverscript in serverscriptservice]

  1. What do you want to achieve?
    I want to get my script to hide a ScreenGUI when on a certain team(Inmate), then when left that team your GUI pops up again.
  2. What is the issue?
    My script is not really running as expected.
local player = game.Players.Localplayer
local teams = game:GetService("Teams")

if player.Team == teams["Inmate"] then
	player.PlayerGui.TeamSwitchGUI.Enabled = false
else
	player.PlayerGui.TeamSwitchGUI.Enabled = true
end
  1. What solutions have you tried so far?
    RoDevs(Discord), and the dev forum. I’m a bit new to scripting.
1 Like
game.Players.Localplayer

Only works on local scripts, if you need this to work with a sever script you could try Remote Events and Functions

Also I dont understand this line:

if player.Team == teams["Inmate"] then

You may need to replace that line with:

if player.Team == game.Teams.Inmate then

local player = game.Players.LocalPlayer -- misspelled here
local teams = game:GetService("Teams"):GetTeams() -- Gets Teams

if player.Team == teams["Inmate"] then
	player.PlayerGui.TeamSwitchGUI.Enabled = false
elseif player.Team `= teams["Inmate"] then -- Should check better than "else"
	player.PlayerGui.TeamSwitchGUI.Enabled = true
end
1 Like

This does the same thing, not really a point of doing this

image
I’m getting a error with this? When Parsing statement it says, I tried equal and equal to.

you are using the wrong statement, its ~=, which means not equal to

Ok, I didnt know you could do that, thx

Oh I never knew that, I’m trying now.

Alright:

==: Exactly Equal to

>: Greater than

<: Less than

>=: Greater than or equal to

<=: Less than or equal to

~=:Not Equal to

1 Like

image
image
I still see the GUI, this is a serverscript in ServerScriptservice should it be like that?

Put it inside StarterGui,

Since you are manipulating a UI, best to put it there.

Should I put it in the ScreenGUI I want to disappear/reappear? or just startergui

Really up to you, I recommend StarterGui ho

Okay, So I put it in startergui(serverscript) and it doesn’t seem to work. I get stack begin/stack end but that’s all.

Sorry, i made a mistake, do this:

local player = game.Players.LocalPlayer -- misspelled here
local teams = game:GetService("Teams") -- Gets Teams
wait() -- Waits so the Player loads (Just for extra security)
if player.Team == teams["Inmate"] then
	print("yes") -- Remove this (I was just Debugging)
	player.PlayerGui:WaitForChild("MainGui").Enabled = false -- The Gui i used (Change it please)
elseif player.Team ~= teams["Inmate"] then
	player.PlayerGui:WaitForChild("MainGui").Enabled = true
end
1 Like

else is actually MUCH better to use in this case

I usually just use elseif to check anyways, just my opinion dont take it seriously

elseif is doing 1 extra step in computation which is unnecessary here.

I understand that, please read my post again, thanks

local player = game.Players.LocalPlayer
local teams = game:GetService("Teams")

while task.wait() do
	if player.Team == teams["Inmate"] then
		player.PlayerGui.TeamSwitchGUI.Enabled = false
	else
		player.PlayerGui.TeamSwitchGUI.Enabled = true
	end
end