The title of the question explains the problem I'm having. I'm making a place for my class and only my classmates can join, I'm currently searching for solutions, if anyone can help me I'll be very happy!
✓ ANSWER ACCEPTED
How to allow certain players to join my place?
4 answers
✓ Accepted answer
Kick everyone else who is not allowed.
local PlayersWhoCanJoin = {} --Insert the players that can join.
game.Players.PlayerAdded:connect(function(plr)
local allowed = false
for i, v in pairs(PlayersWhoCanJoin) do
wait()
if plr.Name == v then
allowed = true
break
end
end
if not allowed then
plr:Kick("You are not allowed to join this place.")
end
end)
Use playeradded, and check and see if their username is somebody in your class.
game.Players.PlayerAdded:connect(function(player)
if player.Name ~= "FRIENDNAME" and player.Name ~= "FRIENDNAME" and player.Name ~= "FRIENDNAME" then player:Kick()
end
end)
Feel free to accept my answer if this helped you.
-- Dictionary table
local admins = {['azarth'] = true}
local players = game:GetService("Players")
local function player_joined(player)
if not admins[player.Name:lower()] then
player:Kick()
end
end
players.PlayerAdded:connect(function(plr)
player_joined(plr)
end)
-- Grab everyone that PlayerAdded didn't connect to in case the script loaded after players joined.
for i,v in pairs(players:GetPlayers()) do
player_joined(v)
end
2 comments
0
You can use game.Players instead of game:GetService("Players")
0
I like using GetService()
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Ok, thanks!