Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I hide GUI after player changes team?

Hello, I have problem with my script. I'd like to create script that hides GUI after player changes on a specific team. Script I had:

local Player = game.Players.LocalPlayer
local TB = game.StarterGui.ScreenGui.Frame

TB.Visible = false

if game.Player.TeamColor == BrickColor.new('Really red') then
         TB.Visible = true
end

Actually worked but It worked only after joining game. But I want to make it execute every time after player changes team.

Script that should work:

local function onTeamColorChanged()
    local TB = game.StarterGui.ScreenGui.Frame
    TB.Visible = false

    if game.Player.TeamColor == BrickColor.new('Really red') then
         TB.Visible = true
    end
end 
Player:GetPropertyChangedSignal("TeamColor"):Connect(onTeamColorChanged)

I want anyone here help me with it.

1 answer

game.Player is not how you index the variable, do Player

local Player = game.Players.LocalPlayer
local TB = Player:WaitForChild("PlayerGui").ScreenGui.Frame -- PlayerGui is what the client see, StarterGui is what server see, so use PlayerGui!!

TB.Visible = false

local function onTeamColorChanged()
    -- local TB = game.StarterGui.ScreenGui.Frame You already made it
    TB.Visible = false

    if Player.TeamColor == BrickColor.new('Really red') then
         TB.Visible = true
    end
end 

onTeamColorChanged()

Player:GetPropertyChangedSignal("TeamColor"):Connect(onTeamColorChanged)

3 comments

0

If you are confused, then tell me

0

Thank you.

0

Works perfectly! Thank you.

This discussion is preserved as it was. New answers, comments, and votes are closed.