Hello, fellow developers,
I want my game to be played only by me and testers for now.
But I have an issue.
What do you want to achieve? To allow only some people to join the game.
What is the issue? It kicks everyone, even the people in the table.
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
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)
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.