Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to allow certain players to join my place?

Asked by 7 years ago

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!

4 answers

Log in to vote
-1
Answered by 7 years ago

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)
Ad
Log in to vote
0
Answered by 7 years ago

Use playeradded, and check and see if their username is somebody in your class.

0
Ok, thanks! advdiscord 17 — 7y
Log in to vote
0
Answered by
Asceylos 562 Moderation Voter
7 years ago
Edited 7 years ago
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.

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
7 years ago
Edited 7 years ago
-- 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
0
You can use game.Players instead of game:GetService("Players") hiimgoodpack 2009 — 7y
0
I like using GetService() Azarth 3141 — 7y

Answer this question