I was making an admin panel and here is the code with 2 errors:
script.Parent.BanButton.MouseButton1Click:Connect(function(player)
local playerGui = player.PlayerGui
local playerNameBox = script.Parent.PlayerNameBox
local banReasonBox = script.Parent.BanReasonBox
local playerToBan = game.Players:FindFirstChild(playerNameBox.Text)
playerToBan.Banned.Value = true
playerToBan.Banned.BanReason.Value = banReasonBox.Text
if playerNameBox.Text == "Name" then
playerGui.BanPanel.MainFrame.BanButton.Text = "Please enter a player to ban"
elseif banReasonBox.Text == "Reason" then
playerGui.BanPanel.MainFrame.BanButton.Text = "Please enter a reason"
else
playerToBan:Kick(banReasonBox.Text) -- Kicks player for the givin reason
end
end)
The first error is on line 15 and 17. "Attempt to index nil with 'PlayerGui'" Another error I got before I added was with the kick part. It is supposed to kick the player in the banReasonBox. Note: This is a local script
What is the problem? Thanks!

1 comment
you could do local player = script.Parent.Parent.Parent or somethin like that.