Is their a way to lock a ROBLOX Server, to prevent players from joining

Hello! So Im trying to make a Elimination game, but you litterly cant come back because if you die or fall of the Baseplate, you get kicked lol. Basically, Im trying to make it so when a event happens then, the server gets locked and anyone who tries to join they get kicked automatically

Here’s my current script:

-- Defining Variables
local TutorialText = game.StarterGui.ScreenGui.TutorialText
local BaseplateStrinkScript = game.Workspace.Baseplate.Script
local playersInServer = #game.Players:GetPlayers()

local PlayerGui = game:GetService("PlayerGui")

-- First Line Of Code
BaseplateStrinkScript.Disabled = true

-- Game Startup
game.Players.PlayerAdded:Connect(function()
	if #game.Players:GetPlayers() == 2,20 then -- Checks if the playerlist has 2 all of the way to 20 players.
		StartTheGame()
	end
end)

local function StartTheGame()
	wait(5)
	PlayerGui.TutorialText.Visible = true
	wait(4)
	PlayerGui.TutorialText.Text = "In this game, Players must use the cars and Knock eachother off the Baseplate!"
	wait(7)
	PlayerGui.TutorialText.Text = "The Baseplate Will Strink Slowly so make sure you dont fall!"
	wait(7)
	PlayerGui.TutorialText.Text = "The Last player Standing Wins!"
	wait(5)
	PlayerGui.TutorialText.Text = "Goodluck, Players!"
	wait(5)
	PlayerGui.TutorialText.Visible = true
	BaseplateStrinkScript.Disabled = false
end

-- Looking For The Winner
local function StopTheGameAWinnerHasBeenChosen()
	BaseplateStrinkScript.Disabled = true
	wait(5)
	PlayerGui.TutorialText.Visible = true
	PlayerGui.TutorialText.Text = "Great Job Player!"
	wait(4)
	PlayerGui.TutorialText.Text = "Looks Like you have Won the game!"
	wait(5)
	PlayerGui.TutorialText.Text = "Your now one of the Best Fighters In Robloxia!"
	wait(7)
	PlayerGui.TutorialText.Text = "You were truley a Bloxer, you Deserve This Medal!"
	wait(5)
	PlayerGui.TutorialText.Text = "Congrats and, Goodbye!"
end

game.Players.PlayerRemoving:Connect(function()
	if #game.Players:GetPlayers() == 1 then
		StopTheGameAWinnerHasBeenChosen()
	end
end)
3 Likes

First off, Woah, Why are the function names so long?
Like, who would want to call StopTheGameAWinnerHasBeenChosen() in their code?

That aside, this is some example code you can put around your remote.

game.Players.PlayerAdded:Connect(function(player)
	print("Player joined, username: " .. player.Name.."! Kicking user, as server is locked..")
player:Kick("Server locked!")
print("Kicked!")
end)
5 Likes

Another way to do this would be to teleport all players to a private server.

1 Like

If I solved your issue, please mark it as a solution!

Names without an S :bomb:

I havent been kicked yet, heres the current script:

wait(5)
game.Players.PlayerAdded:Connect(function(player)
	print("Player joined, username: " .. player.Name.."! Kicking user, as server is locked..")
	player:Kick("The Server locked, the game has already Started!")
	print("Kicked!")
end)
1 Like

anything in the console?

1 Like

I think you may be joining before the PlayerAdded event has been connected. Maybe try manually locking it with a command?

local ServerLocked = false

game:GetService("Players").PlayerAdded:Connect(function(player)
      if ServerLocked then
           player:Kick("Server is Locked")
      end
      player.Chatted:Connect(function(msg)
            if msg == "/lock" then ServerLocked = true end
      end)
end)
1 Like

manually? I cant just be going around servers to lock them, that’s time consuming anyway how did you even think of that : |

No their isn’t anything but from an error from the main script

Create a ServerLocked variable, create a PlayerAdded event at the top of your script, if ServerLocked is true, kick the player by calling :Kick() on the player instance, when the round starts, set ServerLocked to true, when it ends, set ServerLocked to false.

1 Like

What is this? There is no PlayerGui service!?

1 Like

What I would do is change the server size to how many you want it will be so much easier and less time consuming. You do this by going into the create tab. Then you click on the gear icon and it should be configure start place. Then, go to access and change the server size.

Im not a starter so please don’t assume

Yes their is, PlayerGui | Roblox Creator Documentation

Its best to search about something you don’t know

But I have done that for a plain baseplate before which is I made that post.

Im still confused on what your trying to point out, the text when I see it is not understandable

I use the PlayerGui Service so I can make sure that the UI Pops up on the players screen

Why set it to false? if you look at the script at the end when Im looking for the winner then, I make sure that their is one player left, Why would I unlock the server when I want their to be 1 more player?

What do you mean? PlayerGui is NOT a service, it is a Child of a Player Instance…

How come the script didn’t error