How do you make a slocked script?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?

I need help how do you make a locked server script for all servers that can’t be passed unless the script is removed.

  1. What is the issue? Include screenshots / videos if possible!

I am not a great scripter please help.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I have tried looking at some tutorials, and some posts that none of them helped.

There are already many topics that cover this, and you could’ve probably came up with a way to do it by yourself. Here is a link.

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.

Variables
Booleans

Player Service
Player Added Event
Player.Chatted event

Kicking a player

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.

1 Like

Would someone have to be in game to slock the server? Because if so I want no one in the server, but it is locked.

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.