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)
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)
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)
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.
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.
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?