I am trying to make a server lock script for a game I am making, but I have been unsuccessful. It is supposed to make it so new players can’t join when a new game is started. I have tried looking for tutorials online, on the forum, and in the toolbox because I know very little scripting, but all of them are manual ones.
check for when a new player joins the game (after the server is locked), then kick them
You can kick new players if the game has started, but that would be hard for players to join a server if they always get kicked since most of the servers are locked. You can do something like story games do, which they have a lobby server, then when the game has started, teleport the players in a separate server which other people can’t join.
Here is an example code for locking/unlocking via kick:
local lockConnection function lock() lockConnection = game.Players.PlayerAdded:Connect(function(player) player:Kick("This server is locked!") end) end function unlock() if lockConnection then lockConnection:Disconnect() end end
Yes, I want it to be like Camping, Break in, etc. where it teleports a group of people to a server, makes it so other players can’t join them, but they just get put in a new server rather than getting kicked.
You need to teleport everyone in a private server so no one can join them,
If that’s the case then where the code that kicks the player is you put similar code to what teleported them to the locked server so that they get redirected to a different server.
EDIT: actually, do what @TheLordGamer1820 said to do
This is what you should do when you wan’t all the players to be sent to play:
local ts = game:GetService("TeleportService") local plrs = game:GetService("Players") local reseredServerCode = ts:ReserveServer(game.PlaceId) local e = plrs:GetPlayers() ts:TeleportAsync(e)