Help making a script that only allows players to join at certain times

Hello everyone!

I was just wondering, if it is possible to create a script (and how would I create a script) that only allows players into a server at certain times of the day, for example if the player doesn’t join between 19:00 to 21:00 and they try to join out of them opening times it will kick them from the server.

I can’t seem to find any forum topics on it so I thought I would ask.

Thanks!

1 Like

I recommend using os.time for something like this.

You can do either of the following:

  1. Make the game private and only enable it when you want players to join
  2. Put the following code into a server script in serverscriptservice:
game.Players.PlayerAdded:Connect(function()
    if not (os.date("*t",now)["hour"] > 19 and os.date("*t",now)["hour"] < 21) then
         player:Kick("You cannot join now.")
    end
end)

read more about os.time here

EDIT: Please put my answer as a solution if this is what you wanted.

2 Likes

It is what I needed but it doesn’t seem to work.

game.Players.PlayerAdded:Connect(function(player) -- I completly forgot the player argument omg
    if not (os.date("*t",os.time())["hour"] > 19 and os.date("*t",os.time())["hour"] < 21) then
         player:Kick("You cannot join now.")
    end
end)

I forgot the player argument in the function. Whoops

EDIT: ok works now, I tested it in a studio world

1 Like

Thank you, this helped a bunch