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)

2 comments
Perhaps the player left the game. Make your while loop check whether or not 'p' is nil.
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.