Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

When Teleporting Players Between Places, How Can I Carry Data From the Previous Place to the Next?

I'm in the process of making an RPG. Upon entering the game, the player is supposed to meet a title screen with the option to start and load a game. When the player does this, he or she is supposed to be teleported to the main game, but I've encountered a problem.

Let's say that the player has multiple save files with differing levels and currency. When the player is teleported to the next game, how can I make sure that the game loads the correct save file?

I've tried to solve this problem by making it to where if a player loads Save File 1, he or she is teleported to Spawn1 in the next game and touching Spawn1 would load their save information, and the same for Save File 2 and Spawn2, and Save File 3 and Spawn3, and so on. But for some reason, the code for teleporting the player to their corresponding SpawnLocation doesn't work and instead teleports them to a random SpawnLocation in the game.

This is the code I used, and I have no clue as to why it doesn't work.

local TeleportService = game:GetService("TeleportService")
player = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent

wait(1)
script.Parent.MouseButton1Up:connect(function() --When the player clicks this GUI button, the script fires.
	script.Parent.Parent.Parent.Parent.Visible = false
	script.Parent.Parent.Parent.Parent.Parent.Dark.Visible = false
	script.Parent.Parent.Parent.Parent.Parent.NewGameSlots.Visible = false
	local fade = Instance.new("Frame", script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent) --This is just a fade for dramatic effect before the player teleports; there's nothing wrong with it.
	fade.Name = "Fade"
	fade.Size = UDim2.new(1, 0, 1, 0)
	fade.BackgroundColor3 = Color3.new(0, 0, 0)
	fade.Transparency = 1
	fade.ZIndex = 10
	for i = 1, 10 do
		wait(.1)
		fade.Transparency = fade.Transparency - .1
	end
	TeleportService:TeleportToSpawnByName(561825470 , "Spawn1", player) --This is the line where the player is supposed to teleport specifically to Spawn1 in the PlaceId 561825470. While it DOES teleport to 561825470, the player always spawns on a random SpawnLocation.
end)

Is there something wrong with the script? Or better yet, is there a much simpler way of transferring data from the previous place to the next? For example, I'd like a way for the when the player clicks "Slot1", their 1st key in the DataStore is loaded when they join the next game, and if they click "Slot2", their 2nd key is loaded, etc. Is there a way to do this? I've looked all over the ROBLOX wiki and I couldn't find out why my script is wrong or another way of achieving this.

1 answer

For all of your places to be able to access the same data, they must all be saved under one universe/game.

You can find out how it is done by looking at this ROBLOX Wiki Article

Once they are all under one game you will be able to access the same data in each place.

It is mostly self-explanatory in the wiki above, but if you have any questions just ask.

This discussion is preserved as it was. New answers, comments, and votes are closed.