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:
01 | teams = { } |
02 |
03 | Check = function () |
04 | for a,b in pairs (script.Parent:GetChildren()) do |
05 | if b.className = = "BrickColorValue" then |
06 | table.insert(teams, tonumber ( tonumber (#teams)+ 1 ),b.Value) |
07 | end |
08 | end |
09 | if #teams< 1 then print ( "No Team Selection" ) script:Remove() return end |
10 | for c,d in ipairs (teams) do |
11 | if script.Parent.Parent.Parent.TeamColor = = d then |
12 | print ( "OK!" ) |
13 | script:Remove() |
14 | return |
15 | end |
16 | end |
17 | script.Parent:Remove() |
18 | end |
19 | Check() |
So I edited your script, tabbed it correctly, and made it more efficient:
01 | Check = function () |
02 | for a,b in pairs (game:GetService( "Teams" ):GetChildren()) do --You have a bunch of BrickColorValues with the teamColors |
03 | if script.Parent.Parent.Parent.TeamColor = = b then |
04 | print ( "OK!" ) |
05 | script:Destroy() -- You destroy the script if the TeamColor matches? |
06 | return |
07 | end |
08 | end |
09 | if #(game:GetService( "Teams" ):GetChildren())< 1 then print ( "No Team Selection" ) script:Destroy() return end |
10 | script.Parent:Destroy() |
11 | end |
12 | Check() |
However, I don't believe this script really makes sense. Here's a script that accomplishes what I think you were going for.
01 | local guiYouMightBeAbleToView = script.Parent.Parent.Parent |
02 | --[[Everything you want to dissapear should be inside this object, |
03 | but this object has to be a Gui Object, and not a ScreenGui. |
04 | Edit the "script.Parent.Parent" as needed. --]] |
05 |
06 | local player = game.Players:WaitForChild( "LocalPlayer" ) |
07 | local clonedGui |
08 |
09 | Check = function (propertyChanged) |
10 | if propertyChanged = = "TeamColor" then --if the Player's TeamColor property changed |
11 | if player.TeamColor = = "Medium stone grey" then |
12 | guiYouMightBeAbleToView.Visible = true |
13 | else |
14 | guiYouMightBeAbleToView.Visible = false |
15 | end |
Good luck!