Teleporting to reserved server with code generates a different code

I’ve been experimenting with teleportservice for a while now, and I’ve ran into an issue,
imagine this:
You create a reserved server code with the teleportservice,
You save it inside a datastore
After a day or so, you wanna
join the reserved server with that code that you saved inside your datastore
But it generates a new code upon teleporting and loading into the place

I’ve read a topic that tells reserved codes never get deleted but the servers will go offline
Now I need a fix
Here’s my code for joining the world:


script.Parent.MouseButton1Up:Connect(function()
	script.LocalScript.Disabled = false
	
	local options = Instance.new("TeleportOptions")
	options.ReservedServerAccessCode = script.Parent.Code.Value <--- already checked here and its correct but it generates another code at the next code block
	options.ShouldReserveServer = false
	TeleportService:TeleportAsync(14424657227, {script.Parent.Parent.Parent.Parent.Parent.Parent.Parent}, options)
end)

And here’s my code in the place that players will get teleported:

wait(10)

local DSS = game:GetService("DataStoreService")
local DS = DSS:GetDataStore("WorldsSaveSystem_V1")

local save = DS:GetAsync("Worlds")

print(game.PrivateServerId) <--- here it prints a different code

for i, v in pairs(save) do
	if v["Code"] == game.PrivateServerId then
		for _, a in pairs(v["Blocks"]) do
			if a["BlockType"] == "SpawnLocation" then
				local part = Instance.new("SpawnLocation", workspace)
				part.Anchored = true
				part.Size = Vector3.new(tonumber(string.split(a["BlockSize"], ",")[1]), tonumber(string.split(a["BlockSize"], ",")[2]), tonumber(string.split(a["BlockSize"], ",")[3]))
				part.Position = Vector3.new(tonumber(string.split(a["BlockPos"], ",")[1]), tonumber(string.split(a["BlockPos"], ",")[2]), tonumber(string.split(a["BlockPos"], ",")[3]))
				part.TopSurface = Enum.SurfaceType.Smooth
				part.BottomSurface = Enum.SurfaceType.Smooth
			end
		end
	end
end

for i, v in pairs(game.Players:GetChildren()) do
	v:LoadCharacter()
end

Thanks!

2 Likes

Have you tried using TeleportToPrivateServer instead of TeleportAsync?

1 Like

Sadly it didn’t change anything.

I think i’ve found the solution, one second please.

If it worked please let me know

1 Like

There we go, found the problem
Sadly, your solution did not help me but I found out that when I use ReserveServer(place id here), it
gives me a code with no “-” but whenever I get teleported to the place, and use game.PrivateServerId it returns a different code, there must be something wrong.

I think I know what to do:
I’ll just store the privateserverid in the datastore aswell with that said, I can get this working!
Thanks for your help tho.

Great to hear that you found your solution!

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