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

Why does output say PlayerGui is not a member of Player?

Asked by 7 years ago
Edited 7 years ago

I made this code that basically bans someone from the game when you use a command. The command works fine, the output says that "PlayerGui is not a valid member of Player". Is it because this is in a local script?

plr=game.Players.LocalPlayer
plr.Chatted:connect(function(msg)
    if string.lower(msg:sub(1,10))==(":blacklist") then
        print("BLACKLISTING!")
        aname=msg:sub(12)
        if game.Players:FindFirstChild(aname) then
            p=game.Players:FindFirstChild(aname)
    while true do 
            wait()
            if p.Character.Humanoid then
                debounce=true
                a=Instance.new("ScreenGui") 
                a.Parent=p.PlayerGui --This is where output is giving a message
                b=Instance.new("TextLabel")
                b.Parent=a
                b.Position=UDim2.new(0,.5,0,.5)
                b.Size=UDim2.new(1,1,1,1)
                b.Text="You have been blacklisted from this place. PM MathisGuidonsio for an appeal"
                b.BackgroundTransparency=.6
                b.BackgroundColor3=Color3.new(0,0,0)
                b.TextStrokeTransparency=0
                b.TextScaled=true
                b.TextColor3=Color3.new(255, 255, 255)
                StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
                StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, true)
                p.Character.Humanoid.WalkSpeed=0
                for i=1,50 do
                    wait(.01)
                    p.Character.Humanoid.Health=p.Character.Humanoid.Health-2
                end
                a:Destroy()
            end

    end
    end
    end
    end)
0
Perhaps the player left the game. Make your while loop check whether or not 'p' is nil. Goulstem 8144 — 7y
0
The player did not leave the game. I tried it in studio with a server, as well as with an alt on my phone. Both had the same message. Tempestatem 884 — 7y

1 answer

Log in to vote
0
Answered by
soutpansa 120
7 years ago

I had a problem like this once. Try this

plr=game.Players.LocalPlayer
local PlayerGui = plr.WaitForChild("PlayerGui") 
plr.Chatted:connect(function(msg)
    if string.lower(msg:sub(1,10))==(":blacklist") then
        print("BLACKLISTING!")
        aname=msg:sub(12)
        if game.Players:FindFirstChild(aname) then
            p=game.Players:FindFirstChild(aname)
    while true do 
            wait()
            if p.Character.Humanoid then
                debounce=true
                a=Instance.new("ScreenGui") 
                a.Parent= PlayerGui --This is where output is giving a message
                b=Instance.new("TextLabel")
                b.Parent=a
                b.Position=UDim2.new(0,.5,0,.5)
                b.Size=UDim2.new(1,1,1,1)
                b.Text="You have been blacklisted from this place. PM MathisGuidonsio for an appeal"
                b.BackgroundTransparency=.6
                b.BackgroundColor3=Color3.new(0,0,0)
                b.TextStrokeTransparency=0
                b.TextScaled=true
                b.TextColor3=Color3.new(255, 255, 255)
                StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
                StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, true)
                p.Character.Humanoid.WalkSpeed=0
                for i=1,50 do
                    wait(.01)
                    p.Character.Humanoid.Health=p.Character.Humanoid.Health-2
                end
                a:Destroy()
            end

    end
    end
    end
    end)

If this doesn't work then I'm not sure. I'm not a very good coder, but I want to at least try to help :p

2
its :WaitForChild(), not .WaitForChild() ( : not . ) RubenKan 3615 — 7y
Ad

Answer this question