Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Spectating Team Gui. Any help?

Asked by 9 years ago

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:

01teams={}
02 
03Check=function()
04for a,b in pairs(script.Parent:GetChildren()) do
05if b.className=="BrickColorValue" then
06table.insert(teams,tonumber(tonumber(#teams)+1),b.Value)
07end
08end
09if #teams<1 then print("No Team Selection") script:Remove() return end
10for c,d in ipairs(teams) do
11if script.Parent.Parent.Parent.TeamColor==d then
12print("OK!")
13script:Remove()
14return
15end
16end
17script.Parent:Remove()
18end
19Check()

1 answer

Log in to vote
3
Answered by
Validark 1580 Snack Break Moderation Voter
9 years ago

So I edited your script, tabbed it correctly, and made it more efficient:

01Check = 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()
11end
12Check()

However, I don't believe this script really makes sense. Here's a script that accomplishes what I think you were going for.

01local guiYouMightBeAbleToView = script.Parent.Parent.Parent
02--[[Everything you want to dissapear should be inside this object,
03but this object has to be a Gui Object, and not a ScreenGui.
04Edit the "script.Parent.Parent" as needed. --]]
05 
06local player = game.Players:WaitForChild("LocalPlayer")
07local clonedGui
08 
09Check = 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
View all 22 lines...

Good luck!

0
thanks ill test it out! CarterTheHippo 120 — 9y
0
the script has to constantly check for the player's team color, does it do that? CarterTheHippo 120 — 9y
0
It checks each time a property of the Player is modified, which is an event. The :connect part fires the script whenever said event occurs. Validark 1580 — 9y
0
im having trouble actually making it work, I have it pasted inside a frame with the thing at script.Parent CarterTheHippo 120 — 9y
View all comments (2 more)
0
Does it matter that the team you start out on is Medium stone grey? CarterTheHippo 120 — 9y
0
If the Frame is script.Parent, you need to change the beginning of the script to this: "local guiYouMightBeAbleToView = script.Parent" Validark 1580 — 9y
Ad

Answer this question