How do I transfer data from one place in my game to another place?

Basically I want to keep my data when I teleport to each place in my game!

For example:

  • Place 1 (Lobby) I have 50 coins, 1 gun, 1 custom character, Daily rewards (if collected on one of the places it will show same on all places) and other items store with the character.

  • Place 2 (Story game) I have the exact same things from the first place.

  • And so on for any additional place.

if its 2 different games then you cant

but if its a place thats inside of the same game/world, i think you can access the datastores like normal

ive never tried this before dont fact check me

Here is a picture for better understanding!
Screenshot 2023-07-17 032241

yeah then datastores should work normally in those games since badges can also be awarded from places under the same game

For data persistance between session and places, for your use case, use the DataStoreService.

How do I create a DataStoreService that will save the data for all of the places in my game?

DSS = game:GetService("DataStoreService")

local ds1 = DSS:GetDataStore("whatever your datastore is")

https://create.roblox.com/docs/tutorials/scripting/intermediate-scripting/saving-data
Example code: (formatting messed up due to luau string interpolation)

local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")

local playerData = DataStoreService:GetDataStore("PlayerData")

Players.PlayerAdded:Connect(function(player)
	local success, data = pcall(function()
		return playerData:GetAsync(player.UserId) --Yields, may return nil
	end)
	
	if success then
		--If they've never joined before
		if data == nil then
			data = {
				coins = 0,
				inventory = {},
				lastClaimedReward = 0,
			}
		end
		
		--Set their coins, give them their inventory, et cetera
	else
		--[[Probably best to retry getting their data, but for this example we will kick them
		to prevent overriding their data]]
		warn(`Unable to load {player.Name}'s data.`)
		player:Kick("Unable to load your data, please try again later.")
	end
end)

Players.PlayerRemoving:Connect(function(player)
	--Save their data when they leave
end)
1 Like

This post seemed to have a solution you are looking for. How do you save data across games? - #4 by TopBagon

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