Well, the #help-and-feedback:scripting-support category is not for asking for a full script, you should try to get something together before you ask for help. I’ll link some documentation on things you will need for this.
EDIT: Since you aren’t much of a scripter I’ll show en example below of what you would do.
local Players = game:GetService("Players") -- Gets the service for players
local IsServerLocked = false -- Boolean on server start is set to false
local LockCommand, UnlockCommand = "!lock", "!unlock" -- Commands in string format
Players.PlayerAdded:Connect(function(Player)
if IsServerLocked == true then -- Checks if the server is locked
Player:Kick("Server is currently locked!") -- Kicks the player off of the current server
end
Player.Chatted:Connect(function(Message) -- Event gets fired everytime the player has chatted
-- Will use the message to see if it matches the command
if string.lower(Message) == LockCommand then -- Checks if the lowercase version of the users message matches the lock command
IsServerLocked = true -- Sets the boolean to true, locks the server
elseif string.lower(Message) == UnlockCommand then -- Checks if the lowercase version of the message matches the unlock command
IsServerLocked = false -- Sets the boolean to false, Unlocks the server
end
end)
end)
I do find the link your provided to be helpful, but since the OP is not much of a scripter I wouldn’t suggest to use the OnServerEvent bit to change the value of the boolean, rather it’d be better to use a chatted event in this case.
When someone joins an empty server the script is ran, and it kicks that somebody, which will result into the server closing if there was no player that joined right before the first player was kicked.
When the game.Players.PlayerAdded event is fired, check to see if they are an authorized user, maybe use a table of userid’s. Then if they are not authorized, run Player:Kick(“You are not whitelisted”) or something around those lines.