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:

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()

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:

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!

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