Please help me fix this error!

but the script 1 gets its reserved priv server id cause of the join system example we created 4 servers (reserved) and if me and my friend join with ID 4 (gui) we both teleport into same server so yea

Lowkey, some of your code will need to be re-written. I’ll do my best to help you out and re-script it.

For example,

  if DSS:GetDataStore(ID):GetAsync("G") == nil then

This is VERY unhealthy, because no matter how many times you create a new server it will always iterate over it. I’d recommend using that creator.UserId as the Id to see if they have data already saved or not.

we want it to be numbers cause of the long write time

I understand that; however, script2 will never get the mapname because you’re calling the wrong ID in script2

we will check!

thank you for ur feedbacks!!

if workspace:FindFirstChild("Map") then
workspace.Map:Destroy()
end
1 Like

its supposed to do that

and thank for ur feedback to!

if we added print(ID) it prints nil

1 Like

I’d recommend using JoinData to be able to pickup the proper ID on the ReservedServer.

Documentation can be found here.

For example:

---script1
local TS = game:GetService("TeleportService")
local DSS = game:GetService("DataStoreService")

local event = game.ReplicatedStorage.Events.CreateServer
local e2 = game.ReplicatedStorage.Events.JoinServer

event.Event:Connect(function(creator, mapname)
    local tableforjoin = {}
    
    table.insert(tableforjoin, creator)
    
    local reserved = TS:ReserveServer(12607086809)
    local ID = 1
    local canID = false
    
    repeat
        if DSS:GetDataStore(ID):GetAsync("G") == nil then
            canID = true
            DSS:GetDataStore(string.sub(reserved, 1,8)):SetAsync("G", ID)
            DSS:GetDataStore(ID):SetAsync("G", creator.UserId)
            DSS:GetDataStore(ID .. "2"):SetAsync("G", reserved)
            DSS:GetDataStore(ID .. "3"):SetAsync("G", mapname)
        else
            ID += 1
        end
    until canID == true
    
    wait(.1)
    TS:TeleportToPrivateServer(12607086809, reserved, tableforjoin,"",{DSID = ID})
---- {DSID = ID} will create teleportData that the server in script2 can pickup!
end)

e2.OnServerEvent:Connect(function(plr, id)
    local tableforjoin = {}

    table.insert(tableforjoin, plr)
    
    local searchserver = DSS:GetDataStore(id .. "2"):GetAsync("G")
    
    TS:TeleportToPrivateServer(12607086809, searchserver, tableforjoin)
end)
---script2
local DSS = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local reserved = game.PrivateServerId

local ID = nil
local mapname = nil
local initial
function getID(Player)
	local JoinData = Player:GetJoinData()
	if JoinData.TeleportData then
		ID = JoinData.TeleportData.DSID
		mapname = DSS:GetDataStore(ID .. "3"):GetAsync("G")

		if ID and mapname then
			initial:Disconnect()
		end
	end
end
initial = Players.PlayerAdded:Connect(getID)

local newmap = game.ReplicatedStorage.Maps:FindFirstChild(mapname):Clone()
game.Workspace:FindFirstChild("Map"):Destroy()
newmap.Parent = game.Workspace
newmap.Name = "Map"

game.Players.PlayerAdded:Connect(function(plr)
    plr.PlayerGui.ID.TextLabel.Text = ID
end)

Did my solution happen to work for you?

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