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

How do I hide GUI after player changes team?

Asked by 3 years ago

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

Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

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)
0
If you are confused, then tell me Xapelize 2658 — 3y
0
Thank you. Mad_Engine 5 — 3y
0
Works perfectly! Thank you. Mad_Engine 5 — 3y
Ad

Answer this question