Hi! I’m trying to make this script identify a player entering a private server and kicking them from said private server if they’re not in a specific group. Attached is the script I wrote out which is not returning any errors but doesn’t seem to be achieving what I’m looking for. I’m not sure where my error lies so any help is appreciated.
game.Players.PlayerAdded:Connect(function(p)
local whitelisted = true
if game.PrivateServerId == "" then
if player:IsInGroup(13042215) then
whitelisted = true
end
if not whitelisted then
p:Kick("Please join the group in order to access our private servers!")
else
end
end
end)```
A private server should have a valid ID. Imagine this script runs in a private server, and you’re checking if the ID is nothing, which this if statement evaluates to false, leading to everyone who joined the server gets kicked out.
You can fix this by checking if the server has a valid private server ID and if the player is in the group using one if statement with the and operation.
--//Services
local Players = game:GetService("Players")
--//Controls
local GroupId = 13042215
local PrivateServerId = 0000000 --//Fill this out with your group's private server id
--//Functions
Players.PlayerAdded:Connect(function(player)
if game.PrivateServerId == PrivateServerId then
if not player:IsInGroup(GroupId) then
player:Kick("Please join the group in order to access our private servers!")
end
end
end)