So, basically I am trying to make a admin command but whenever I say "game.Players.LocalPlayer.Name" it always get a error called "attemp to index nil with "Name""

Here is the whole code:

local prefix = "/"
local targettokick 
local admins = {"scooter369","airstrike0103"}

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)

		local messagesplit = message:split(" ")
		local splittoo = messagesplit[1]:split("/")
		splittoo[2] = string.lower(splittoo[2])

		
		if splittoo[2] == "kick" then
			for i, v in pairs(admins) do
				if game.Players.LocalPlayer.Name == v then
					print("Player admin")
				else
					print("player not admin")
				end
			end				
			targettokick = messagesplit[2] 
			if game.Players:FindFirstChild(targettokick) then
				game.Players[targettokick]:Kick("You have been kicked from the game..")
			end
		end
	end)
end)

If you want to get in the line where I get the error, Go to line 15..

help pls

7 comments

0

Is it in a local script

0

instead of game.Players.LocalPlayer == v try player.Name == v, since you've already got the player from the playeradded event

0

its not in local script

0

Thank you Warphi.

0

Nope, Now it always says that player is not an admin.

0

I messed up the script and it works now, thank you all anyways,

0

Is it just me or do I see a extra 'end)' in the code?