How to make un-authorized player kicker script "(Developers Only) Game'

I need a script which kicks un-authorized player, but i keep searching for a tutorial but i cant see one. Help me

1 Like

Very simple. Simplest solution:

Insert a Script in ServerScriptService.
Code:

local Whitelisted = {123,456,789} -- Use player ids as its more secure if a player was to change their username.

game.Players.PlayerAdded:Connect(function(player)
for i,v in pairs(Whitelisted) do
    if player.UserId == v then -- they're whitelisted!
        print("Developer allowed to join!")
    else -- their id wasnt found in the table
        player:Kick("You are not whitelisted!")
    end
    end
end)

Yep! As easy as that!
EDIT: Fixed formatting.

9 Likes

On mobile sorry for poor formatting!

2 Likes

Thanks! man where can I learn script like you? :grin:

1 Like

It is ok at least i understand it now

1 Like

If you’re starting out, it’s best to know what you really want to learn. Start with the basics. Youtube tutorials and then start using the Developer Wiki which is a really great resource for examples and somethint called API referencing which you can use to research a specific function or service and learn its use!

Good luck in your future projects! Scripting is a lot of fun.

3 Likes

Thanks dude I will see and try like that Thanks for the solution!
and I know scripting will be fun

4 Likes

No sir it is for my game not for a group game
See im testing my game but I need to make it public because in the output it says: “You must publish the game to access DataStore”. But im getting ready for a big update and i dont want the players to see the update. so I made another place but only for developers

1 Like

You don’t even need a script for this, there’s native support.

See the permissions section in the following article:
https://developer.roblox.com/en-us/articles/game-settings

Release announcement is here:
https://devforum.roblox.com/t/introducing-unified-game-permissions/428956

1 Like

Yeah but thats locking a game for developers only with game edit access.

This way I guess you can have the game public and still have the specific people you want join.

2 Likes

Game access permissions isn’t limited to Studio access. The first permission level, Play, allows users to play a game while it is closed without also granting them further access to your games. It has its respective benefits, such as in group games where you have a tester rank in a public join group: giving testers the “Play” permission will allow them to join the game while other members in the community rank cannot, voiding the need for a script at all.

1 Like

You can make the place private, so only you can join:


This is on the Develop page

Thank you thou i have only know it now

Im working with my dev friend so that we can edit the game

1 Like

Note: This will kick anyone that isn’t at index 1 of the table. You should add a variable for finding in the table then deal with it after looping the table.

1 Like

so is the script wrong and must be added? just tell me please

Here’s an edited version of the script provided by @b_oolean

local Whitelisted = {123,456,789} -- Use player ids as its more secure if a player was to change their username.

game.Players.PlayerAdded:Connect(function(player)
local isWhitelisted = false
for i,v in pairs(Whitelisted) do
    if player.UserId == v then -- they're whitelisted!
        print("Developer allowed to join!")
        isWhitelisted = true
    end
    end
if not isWhitelisted then
player:Kick("Not whitelisted")
end
end)

(On mobile, indenting not great)

2 Likes

It’s completely unnecessary to loop through the table, you can just use table.find(),

local Whitelisted = {123,456,789} -- Use player ids as its more secure if a player was to change their username.

game.Players.PlayerAdded:Connect(function(player)
    if not table.find(Whitelisted,player.UserId) then
        player:Kick("Not whitelisted")
    end
end)
2 Likes

Good catch, I keep forgetting it exists.

No worries, there’s no major difference other than the script being shorter.

2 Likes