Trying to make a script that disables a button depending on their team

Hello, I’m trying to make a GUI button invisible depending on the team they’re on, doesn’t seem to work though. It’s a local script inside the button. Excuse the very rudimentary programming I don’t have a lot of experience and I’ve just begun learning. Thanks!

local player = game.Players.LocalPlayer
local teamcolors = {"Bright blue", "Maroon", "Plum","Electric blue","Cocoa"}

local function teamcheck()
	if player.TeamColor == "Bright blue" then
		script.Parent.Visible = false
	end
	if player.TeamColor == {"Maroon", "Plum","Electric blue","Cocoa"} then
		script.Parent.Visible = true
	end
	
end

while true do
	teamcheck()
	wait(1)
end
1 Like

I would set a table of team colors that are disabled from the button and another that can see the button. Also, it needs to be a color and not just a name.

local player = game.Players.LocalPlayer
local cantsee = {
	BrickColor.new("Bright blue")
}
local cansee = {
	BrickColor.new("Maroon"),
	BrickColor.new("Plum"),
	BrickColor.new("Electric blue"),
	BrickColor.new("Cocoa")
}

player:GetPropertyChangedSignal("TeamColor"):Connect(function()
	if table.find(cansee, player.TeamColor) then
		script.Parent.Visible = true
	elseif table.find(cantsee, player.TeamColor) then
		script.Parent.Visible = false
	end
end)
1 Like
local Game = game
local Script = script
local Teams = Game:GetService("Teams")
local Players = Game:GetService("Players")
local Player = Players.LocalPlayer
local Parent = Script.Parent --Reference to 'GuiObject'.

local Whitelist = {"RedTeam", "BlueTeam", "YellowTeam", "GreenTeam"} --Array of team names.

local function OnTeamChanged()
	Parent.Visible = table.find(Whitelist, Player.Team.Name)
end
Player:GetPropertyChangedSignal("Team"):Connect(OnTeamChanged)
OnTeamChanged() --Explicitly call the function (in case player is assigned a team before the script runs).