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

Why is my script complaining a gui is not part of PlayerGui?

Asked by
Seyfert 90
8 years ago
Edited 8 years ago

I have this script and when there are multiple people in my game I get the error saying that "playercheckgui9" is not a valid member of PlayerGui

local repStorage = game:GetService("ReplicatedStorage")
local event = repStorage:WaitForChild("BossDied") 

game.Players.PlayerAdded:connect(function(plr)
    local client = game.Players.LocalPlayer
    plr.CharacterAdded:connect(function(chr)
        chr:WaitForChild("Humanoid").Died:connect(function()
            print('Boss Died')
            if plr.TeamColor == BrickColor.new("Bright red") then
                for i, v in pairs(game.Players:GetChildren()) do
                    local guis = v.PlayerGui:GetChildren()
                       for _, v in pairs(guis) do
                             if v.Name == "Shop" or v.Name == "TouchGui" then
                        else
                        v:Destroy()     
                        end
                    end 
                end 
                for i, v in pairs(game.Players:GetChildren()) do
                    if v.TeamColor == BrickColor.new('Bright red') then
                        v.TeamColor = BrickColor.new("Bright yellow")
                    end
                    v.Character.Humanoid:UnequipTools()
                    if v.Character.Humanoid ~= nil then
                        v.Character:BreakJoints()
                    end
                end 
                for i, v in pairs(game.Players:GetChildren()) do    
                    local player = v:FindFirstChild("PlayerGui")
                    local screengui9 = Instance.new('ScreenGui', player) 
                    screengui9.Name = "playercheckgui9"
                    -- Create textLabel
                    local textLabel9 = Instance.new('TextLabel', player.playercheckgui9)
                    textLabel9.Position = UDim2.new(0.45, 0, 0.4, 0)
                    textLabel9.Size = UDim2.new(0, 250, 0, 100)
                    textLabel9.FontSize = "Size28"
                    textLabel9.BackgroundTransparency = "1"
                    textLabel9.TextStrokeTransparency = "0" 
                    textLabel9.Text = ("Round Over")
                end     
                for i=1, 50 do  
                    for i, v in pairs(game.Players:GetChildren()) do
                        local label = v.PlayerGui.playercheckgui9.TextLabel
                        label.TextColor3 = Color3.new(math.random(), math.random(), math.random())
                    end
                    wait(0.1)
                end
        wait(5)
                for i, v in pairs(game.Players:GetChildren()) do
                local playergui = v:FindFirstChild("PlayerGui")
                    if playergui then
                    local somegui = playergui:FindFirstChild("playercheckgui9")
                        if somegui then
                            somegui:Destroy()
                            print("Destroyed ninth GUI in PlayerGui")
                        end
                    end
                end 
            end 
        end)
    end)
end)

1
Is this a normal script or a local script? jjwood1600 215 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

Your using a local script (As shown by local client = game.Players.LocalPlayer). However later on you try to make a change to other players. You should use a server script however it will require a change to your script.

Ad

Answer this question