Server lock script not working

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

  1. What do you want to achieve? Keep it simple and clear!
    I wanna make it so that any player that joins after 120 seconds in the server have passed will get teleported to a different server

  2. What is the issue? Include screenshots / videos if possible!
    It doesn’t work and i don’t know why

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Yes, my whole script is based on the developer hub page

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
So in case you don’t understand how this works, imagine you’re doing an event and don’t want anyone to enter too late, well you’d close the doors after 2 minutes and that’s what i am trying to do here

local TS = game:GetService("TeleportService")
	local DSS = game:GetService("DataStoreService")
	local DS = DSS:GetGlobalDataStore()
	local Players = game:GetService("Players")
	local code = DS:GetAsync("ReservedServer")
	if type(code) ~= "string" then -- None saved, create one
		code = TS:ReserveServer(game.PlaceId)
		DS:SetAsync("ReservedServer",code)
		wait(120)
	Players.PlayerAdded:Connect(function({player})
		TS:TeleportToPrivateServer(game.PlaceId,code,{players})
		end)
	end

you’re trying to teleport the whole players service
this should work.

local Players = game:GetService("Players"):GetPlayers()
Players.PlayerAdded:Connect(function()
	TS:TeleportToPrivateServer(game.PlaceId,code,Players)
end)
local Game = game
local Players = Game:GetService("Players")
local TeleportService = Game:GetService("TeleportService")

local function OnPlayerAdded(Player)
	task.wait(120) --Wait for 120 seconds.
	TeleportService:TeleportToPrivateServer(PlaceId, AccessCode, {Player}) --Attempt the teleport.
end

Players.PlayerAdded:Connect(OnPlayerAdded)

https://developer.roblox.com/en-us/api-reference/function/TeleportService/TeleportToPrivateServer

You didn’t understand, i don’t want everyone to be kicked after 120 seconds, i want it so that everyone who tries to join after 120 server seconds have passed will be teleported to another server, or else this will just be an endless loop of getting teleported into different servers

If I understood it right it should teleport only the guy who joined after 120 seconds and so on. It should work Ig. Try it out in Roblox Studio.

1 Like

yes, so technically the server is locked after 120 seconds

local Game = game
local Players = Game:GetService("Players")
local TeleportService = Game:GetService("TeleportService")

local State

local function OnPlayerAdded(Player)
	if not State then return end
	TeleportService:TeleportToPrivateServer(PlaceId, AccessCode, {Player}) --Attempt the teleport.
end

Players.PlayerAdded:Connect(OnPlayerAdded)

task.wait(120)
State = true

Thanks for explaining yourself a little better this time.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.