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