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

GUI and backpack won't show when players team is changed?

Asked by
OldBo5 30
6 years ago
Edited 6 years ago

So, when a player is on the "Host" team or becomes a host, I want the player to have a GUI pop up as soon as that happens.

while wait() do
local plr = game.Players:GetPlayerFromCharacter()
    if plr.TeamColor == BrickColor.new("Really red") then
        local gui = game.ReplicatedStorage.HostUI
        gui.Parent = game.Players.LocalPlayer.PlayerGui
        wait(1)
        gui.HostFrame.Visible = true
        local k = game.ReplicatedStorage.kill:Clone()
        wait()
        k.Parent = plr.Backpack
end
end

Any problems with this script?

2 answers

Log in to vote
0
Answered by
Leamir 3138 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

Hello, OldBo5!

Try this script:

game.Players.PlayerAdded:Connect(function()
    for i,plr in pairs(game.Players:GetChildren()) do
        if plr.TeamColor == BrickColor.new("Really red") then
            print(plr.Name .. " is on Really Red Team!")
            local gui = game.ReplicatedStorage.HostUI
            gui.HostFrame.Visible = true
            game.ReplicatedStorage.kill:Clone().Parent = plr.Backpack
        end
    end
end)

ATTENTION: This script will work until player leaves the team!

Good Luck with your games!

Ad
Log in to vote
0
Answered by 6 years ago
local plr = game:GetService("Players").LocalPlayer --Define my player

repeat 
    plr:GetPropertyChangedSignal("Team"):wait() 
until plr.Team.Name == "Host" --Everytime the Team property changes, check if it's host, if it is then stop waiting
local gui = game.ReplicatedStorage.HostUI:Clone() --Make a clone of the gui
gui.Parent = plr.PlayerGui -- Put the gui inside of the PlayerGui
wait(1)
gui.HostFrame.Visible = true
local k = game.ReplicatedStorage.kill:Clone()
wait()
k.Parent = plr.Backpack

Answer this question