Problems with re-using code for private server

I tried to use the same code twice to teleport to a private server so that one player create a private server and takes the code with him from the reserved server, then he can invite another player in the first (public) server and send the reserved server code with the invite. it works for transferring over the code and re using it but when I try to teleport to the private server with the same code I get this error code, how do I fix it or is it just impossible?

1 Like

What are you trying to use this for?

sort of party system where in the first place that is created, there can only be one player and the private server (different place, same game) with more then 1 player

Could you actually show your code so that we can see what exactly you’re doing? It’s difficult to help you if you don’t supply any code.

2 Likes

It says it all in the error, once that server is closed, the code is recycled

Because the reservedserver doesn’t exist, once all the players leave the reserved server I’m fairly sure it no longer existed. You’re better off creating a datastore which tracks what servers players are in, then using a friend system allowing the party members to be able to join their friends server via the reserved server ID fetched from the data store

no the server still excisted when showing the error code

I think it’s just impossible to re use the code

Can you recommend me something to do it via another way?

Hello, my request has still not been answered.

If you’re hoping for actual help in this category resolving a specific code problem rather than a conceptual one, you need to show the code you’re working with. That’s why we can only give you prospective answers - we don’t know your implementation, so we can only guess.

Furthermore, this category isn’t for spoon feeding code, so it’s not exactly better to write a whole new chunk for you either - doesn’t teach you anything and you don’t learn where your mistake was and how to fix it. Please read the category guidelines: supply code.

Yes I know, I usually include the script but It’s a bit complex with alot of scripts and remote functions, I think I just found the solution that it’s impossible to re use the reserved server code and I got to do it via another way…

I Also didn’t ask for a whole code or something, just a way like using a function or something

Send the script so we can help you with your issue. Hard to understand your problem without seeing your script.

alright then, don’t mind my scripting skills because I am not that advanced

scripts on the server in the first place:
InviteScript

local messagingService = game:GetService("MessagingService")

messagingService:SubscribeAsync("InvitePlayer", function(RecieverName)
	
	print(RecieverName.Data)
	local Reciever = game.Players:FindFirstChild(RecieverName.Data)
	game.ReplicatedStorage.Invite:FireClient(Reciever)
	
end)

messagingService:SubscribeAsync("InviteCode", function(Code)
	
	print(Code.Data)
	game.ReplicatedStorage.InviteCode:FireAllClients(Code.Data)
	
end)

JoinScript

local players = game:GetService("Players")
local tp = game:GetService("TeleportService")

game.ReplicatedStorage.Join.OnServerEvent:Connect(function(Code)
	
	local plrs = players:GetPlayers()
	print(Code)
	tp:TeleportToPrivateServer(4315535044, Code, plrs)
	
end)

CreateServerScript

local players = game:GetService("Players")
local tp = game:GetService("TeleportService")

game.ReplicatedStorage.CreateParty.OnServerEvent:Connect(function()
	
	local plrs = players:GetPlayers()
	local code = tp:ReserveServer(4315535044)
	print (code)
	tp:TeleportToPrivateServer(4315535044, code, plrs, "spawn", tostring(code))
	
end)

local scripts in the first place:

JoinButtonScript

game.ReplicatedStorage.Invite.OnClientEvent:Connect(function()
	
	script.Parent.Visible = true
	
end)

game.ReplicatedStorage.InviteCode.OnClientEvent:Connect(function(Code)
	
	script.Parent.Code.Value = Code
	
end)

script.Parent.MouseButton1Click:Connect(function()
	
	game.ReplicatedStorage.Join:FireServer(script.Parent.Code.Value)
	
end)

CreateServerScript

script.Parent.MouseButton1Click:Connect(function()
	
	game.ReplicatedStorage.CreateParty:FireServer()
	
end)

Server scripts for the second place:

local messagingService = game:GetService("MessagingService")

game.ReplicatedStorage.Invite.OnServerEvent:Connect(function(Inviter, RecieverName)

	messagingService:PublishAsync("InvitePlayer", RecieverName)
	
end)

game.ReplicatedStorage.InviteCode.OnServerEvent:Connect(function(Inviter, code)
	
	messagingService:PublishAsync("InviteCode", code)
	
end)

local scripts second place:
RecieveCodescript

local TeleportService = game:GetService("TeleportService")

local code = TeleportService:GetLocalPlayerTeleportData()

print(code)

script.Parent.ScreenGui.Code.Value = code

FriendListScript

local player = game.Players.LocalPlayer
local friends = player:GetFriendsOnline(10)
local temp = game.ReplicatedStorage.Template

wait(1)
for i,v in pairs(friends) do
	
	if v.PlaceId == 275797843 then	
	local NewFrame = temp:clone()
	NewFrame.PlayerName.Text = v.UserName
	NewFrame.Parent = script.Parent.ScrollingFrame
	NewFrame.UserName.Value = v.UserName
	NewFrame.Avatar.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=150&y=150&Format=Png&username="..v.UserName	
		
else
		
		local NewFrame = temp:clone()
		NewFrame.InviteButton.Visible = false
		NewFrame.Avatar.Visible = false
		NewFrame.Parent = script.Parent.ScrollingFrame
		NewFrame.PlayerName.Text = "no friends online"	
		

	end
end

InviteButtonScript

script.Parent.MouseButton1Click:Connect(function()
	
	game.ReplicatedStorage.Invite:FireServer(script.Parent.Parent.UserName.Value)
	game.ReplicatedStorage.InviteCode:FireServer(script.Parent.Parent.Parent.Parent.Code.Value)
	
end)

Image first place

Schermopname (18)

Image Second place:

Schermopname (19)

@colbert2677