Rejoin script keeps resetting disconnecting and resetting progress

I have a button in my game that when pressed, rejoins you into the same game, a rejoin button. The issue I’m having is that whenever its pressed, 90% of the time I get error code 285: client initiated disconnect. and then 50% of the time when that happens, it resets the players leaderstats. Keep note my game is small and more often than not, there is only 1 person in the server doing the rejoins, I don’t know if that has anything to do with it.

here is my rejoin script, I can’t seem to find any better or more efficient scripts on devforum, every post is just this:

script.Parent.MouseButton1Click:Connect(function()
	game:GetService("TeleportService"):Teleport(game.PlaceId)
end)

Any type of help is greatly appreciated.

You can’t use TeleportService in studio.

If you need leaderstats to save/load you’ll never to make use of a DataStore, alternatively you can send teleport data.

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

I’m not talking about testing in studio. I’m talking about playing in the actual game

I have a datastore set up already, and I’ve tried to have the datastore save when pressing the rejoin button, but whether or not that works, it still sets your stats back to zero once you’ve rejoined with the button

Here is the issue:

once the last player in the server leaves the game, the server shutdowns. The shutdown takes different amount of time each time, which can cause the player trying to join a server which is currently being shutdown so that explains the error which occurs.

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

players.PlayerAdded:Connect(function(player)
	task.wait(5)
	local privateServerCode = teleports:ReserveServer(game.PlaceId)
	teleports:TeleportToPrivateServer(game.PlaceId, privateServerCode, {player})
end)

As stated, when you teleport the last player of a server that server is scheduled for shutdown, if the player is then teleported to that same server you will encounter the aforementioned error, to get around this you just need to create (reserve) an additional server of the same game and teleport the player there instead.

1 Like

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