Whats wrong with this script?

I get this error message image

Line 354

Line 1758 image

Players.PlayerAdded:Connect(function(Player)
	if not Player:IsInGroup(4585589) and Player.UserId > 0 then
	end
	wait(2)
	if (Player.UserId == 1000 or Player.Name == "Anymoose") then
		Player:Kick("rip bozo")
	end
end)
Players.PlayerAdded:Connect(function(Player)
	if not Player:IsInGroup(4585589) and Player.UserId > 0 then
	end
	wait(2)
	if (Player.UserId == 1000 or Player.Name == "Anymoose") then
		Player:Kick("rip bozo")
	end
end)

I’ve replaced the code with the one you wrote now I’m getting errors such as image

do i need to create a variable for player?

Yeah, you should try that, at beginning do

local Player = game.Players.LocalPlayer

I wrote that code, and no that code works without the declaration of a player variable. You must be attempting to access a player object somewhere else in the script.

To explain it better the PlayerAdded event when fired automatically sends the player object (which caused the event to fire) to the function connected to the event which is handled by the parameter which you have named “Player”. Player will only be valid within the connected function itself and not the entire script so any reference to Player outside of the aforementioned function will require the variable (which is a reference to the player object) to be declared in the same scope in which an attempt is being made to reference the player.

You can declare a Player variable globally by using “local Player = game.Players.LocalPlayer” but this will only work for local scripts.

2 Likes

Make sure to format your document (Right click → Format Document).

Once you did that, you need to add an extra end after the “if not” statement in the PlayerAdded event. Add a ) after that and you’re done!

Making sure your code is clean and organized + formatted is the best way to find the errors in your code.

I’ll just leave all the ends and ifs and functions to find out what’s the problem in your earlier code:

Players.PlayerAdded:Connect(function(Player) --I'll tag this function 1, you'll see why
   if ... then --conditional statement is 2
      ...
   end --this closes 2, ending should start with the biggest tag (between my tags 1 and 2, tag 2 has to end first (that's the rule))

   delay(2, function() --Since the earlier tag 2 was closed, we will now use this as tag 2
      if ... then --tag 3
      ...
      end --ends tag 3
   end) --ends tag 2
--You forgot to close tag 1, the function connected to player added!

Note that I’m just tagging them using comments, not using any special code to tag them or anything