Unable to kick Player via player.UserId

bannedid = {
	"77590021", --using my own ID as an example
}

game.Players.PlayerAdded:Connect(function(plr)
	for i, v in pairs(bannedid) do
		if plr.UserId == v then
			plr:Kick("kick")
		end
	end
end)

I have no idea why this does not work. No output errors or anything. It does work with usernames, but not UserId and I’d rather use the ID.
Thanks in advance.

3 Likes

remove the comma at the start
remove the quotation markz!
also try this:

bannedid = {
	77590021
}
game.Players.PlayerAdded:Connect(function(plr)
    if table.find(bannedid,plr.UserId) then
		plr:Kick("You have been kicked")
	end
end)
5 Likes
  1. remove the “”
  2. make sure that the script is a script in ServerScriptService
  3. would recommend using @oscoolerreborn 's script. Same function, but easier to manage.
2 Likes

ServerScriptStorage? Dayum! Would be useful not gonna lie! But yeah, remove the quotations and ServerScriptService!

when did roblox add ServerScriptStorage?

I think they mean ServerStorage.

1 Like

Meant ServerScriptService, my fault guys :smile:

3 Likes

You don’t necessarily have to remove the comma though, and this same leeway is found in Javascript, just so long as the } isn’t found in the same line as the last comma.

So this is fine (for example):

local t = {
    0,
    1,
}

But this kind of format will error if there is no value after the last comma:

local t = {0,1,}
2 Likes

Also another question, does anyone know why using "\n" in the message for a kick does not create new lines? It does disappear/create a space but it doesn’t create new lines.

plr:Kick("kick \n \n \n you were kicked")

image

[[
kick

lol
]]

does not work either

solution:

Probably a response to games that would create infinitely long lines of text. The kinds of scripts I saw in script games would fill as much space as possible when you were kicked by them, which would be annoying.

Even then, I am not sure why else line breaks are disabled, since after all, it’s not like it’s blocking any critical buttons or something.

1 Like

roblox disabled new lines in a Kick message so if people tried to do “lol \n lol \n lol. etc” it would block out the Leave button (even though you can exit with Alt f4 or turn off your phone)

1 Like