This script works to an extent. It checks and sees what team you are on and if you are not on the correct team you cannot view the gui (at start of game). But however if you change teams in the middle of a game it does not remove the gui. I want this script to be removed from the players screen or just not visible, but when they go back to the team that can view the gui, the gui pops back up. The Medium stone grey team can veiw the gui and the Bright red, and Bright blue team are not allowed to.
This is the script:
teams={} Check=function() for a,b in pairs(script.Parent:GetChildren()) do if b.className=="BrickColorValue" then table.insert(teams,tonumber(tonumber(#teams)+1),b.Value) end end if #teams<1 then print("No Team Selection") script:Remove() return end for c,d in ipairs(teams) do if script.Parent.Parent.Parent.TeamColor==d then print("OK!") script:Remove() return end end script.Parent:Remove() end Check()
So I edited your script, tabbed it correctly, and made it more efficient:
Check = function() for a,b in pairs(game:GetService("Teams"):GetChildren()) do --You have a bunch of BrickColorValues with the teamColors if script.Parent.Parent.Parent.TeamColor == b then print("OK!") script:Destroy() -- You destroy the script if the TeamColor matches? return end end if #(game:GetService("Teams"):GetChildren())<1 then print("No Team Selection") script:Destroy() return end script.Parent:Destroy() end Check()
However, I don't believe this script really makes sense. Here's a script that accomplishes what I think you were going for.
local guiYouMightBeAbleToView = script.Parent.Parent.Parent --[[Everything you want to dissapear should be inside this object, but this object has to be a Gui Object, and not a ScreenGui. Edit the "script.Parent.Parent" as needed. --]] local player = game.Players:WaitForChild("LocalPlayer") local clonedGui Check = function(propertyChanged) if propertyChanged == "TeamColor" then --if the Player's TeamColor property changed if player.TeamColor == "Medium stone grey" then guiYouMightBeAbleToView.Visible = true else guiYouMightBeAbleToView.Visible = false end end end Check() player.Changed:connect(Check) --Fires when a property of the Player changes --By default it sends 1 argument to the called function: Property that changed
Good luck!