Non-tester kicker

Hello, fellow developers,
I want my game to be played only by me and testers for now.
But I have an issue.

  1. What do you want to achieve? To allow only some people to join the game.

  2. What is the issue? It kicks everyone, even the people in the table.

  3. What solutions have you tried so far? Nothing much. I am asking here for the first time.

The code (it is regular script in ServerScriptService) :

local usern = {1619504933, 2203227173} -- other testers will be added
local player = game:GetService("Players")
local kickMessage = "Not finished."

game.Players.PlayerAdded:Connect(function(player)
	if player.UserId ~= usern then
		player:Kick(kickMessage)
	elseif player.UserId == usern then
		print("Safe to pass.")
	end
end)

Any kind of help is appreciated, thank you in advance :slight_smile:

1 Like

You should use table.find for this

Try this, it should help :)

local usern = {1619504933, 2203227173} -- other testers will be added
local player = game:GetService("Players")
local kickMessage = "Not finished."

game.Players.PlayerAdded:Connect(function(player)
	if table.find(usern, player.UserId) == nil then -- Finds user id from table
		player:Kick(kickMessage)
	else
		print("Safe to pass.")
	end
end)
4 Likes

It works perfect, but it must be " == nil", not “~=”.
But anyways thank you!

It should work with nil.

table.find finds the index of a certain value (your certain value being your UserId’s). If the function finds the user id in the table, it will return a number for where it is

For example, if we have the table {"cherrys", "bananas", "apples"} and we want to find where “apples” is in the table, we’d do table.find(t, "apples") and it will return 3.

If there is no “apples” in the table, for example {"cherrys", "bananas", "oranges"} and we ran table.find(t, "apples"), it’ll return nil.

Which means if a user isn’t found in your usern table, the table.find function will return nil, not null. I didn’t even know null existed in Roblox.

1 Like

It still works, but thank you for the advice on the tables.find . Have a great day!

(“null” was a typo)

1 Like

Oh right yeah sorry I didn’t notice I put ~= instead of == sorry :sweat_smile:

1 Like

I’d personally use if not table.find(table, value) then.

2 Likes