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!
Your supposed to reference the player using:
local Player = game.Players.LocalPlayer
Also keep in mind to check if the player thats inputted exists. It might lead to errors later.
if playerToBan then playerToBan:Kick(banReasonBox.Text) end
Have a great day!
I don't think player is a parameter of mousebutton1click.
at the 3rd line, change
local playerGui = player.PlayerGui
to
local playerGui = game.Players.LocalPlayer.PlayerGui
this is because player is not a parameter of Gui.MouseButton1Click event. Instead, it is a parameter for ClickDetector.MouseClick event.