How do i share datastores across places?

  1. What do you want to achieve? Keep it simple and clear!
    So basically i have an stat which is gettable by killing boss in other place, how do i transfer that stat in main game?
  2. What is the issue? Include screenshots / videos if possible!
    Idk how to do that
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tryed to find any, but i didn’t understand a lot

My script in boss place:

local playersService = game:GetService("Players")
local dataStores = game:GetService("DataStoreService")
local dataStore = dataStores:GetDataStore("DataStore")

local protectedCall = pcall

local function onPlayerJoined(player)
	local StatsFolder = Instance.new("Folder")
	StatsFolder.Name = "Stats"
	StatsFolder.Parent = player
	
	local LeafStat = Instance.new("BoolValue")
	LeafStat.Name = "LeafStat"
	LeafStat.Parent = StatsFolder
	local success, result = protectedCall(function()
		return dataStore:GetAsync("Data_"..player.UserId)
	end)

	if success then
		if result then
			if type(result) == "table" then
			LeafStat.Value = result[1] or false
			end
		end
	else
		warn(result)
	end
end

local function onPlayerLeft(player)
	local success, result = protectedCall(function()
		return dataStore:SetAsync("Data_"..player.UserId, {player.StatsFolder.LeafStat.Value})
	end)

	if success then
		print(result)
		print("Everything success")
	else
		warn(result)
		warn("everything wrong")
	end
end

local function onServerClosed()
	for _, player in ipairs(playersService:GetPlayers()) do
		local success, result = protectedCall(function()
			return dataStore:SetAsync("Data_"..player.UserId, {player.StatsFolder.LeafStat.Value})
		end)

		if success then
			print(result)
		else
			warn(result)
		end
	end
end

playersService.PlayerAdded:Connect(onPlayerJoined)
playersService.PlayerRemoving:Connect(onPlayerLeft)
game:BindToClose(onServerClosed) 

I found some topics about that, but still can’t get anything

Is your boss place and main place in the same universe/game?
If so, they automatically carry over so you could create a datastore in place 1 and access it no problem in place 2.

Of course in same, but how do i access it from other script like here is my main game script what line should i add?

local playersService = game:GetService("Players")
local dataStores = game:GetService("DataStoreService")
local dataStore = dataStores:GetDataStore("DataStore")

local protectedCall = pcall

local function onPlayerJoined(player)
	local StatsFolder = Instance.new("Folder")
	StatsFolder.Name = "Stats"
	StatsFolder.Parent = player
	
	local SecretStatsFolder = Instance.new("Folder")
	SecretStatsFolder.Name = "SecretStats"
	SecretStatsFolder.Parent = player
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local clicks = Instance.new("IntValue")
	clicks.Name = "Clicks"
	clicks.Parent = leaderstats

	local money = Instance.new("NumberValue")
	money.Name = "Money"
	money.Parent = leaderstats

	local rebirths = Instance.new("IntValue")
	rebirths.Name = "Rebirths"
	rebirths.Parent = leaderstats
	
	local memory = Instance.new("IntValue")
	memory.Name = "Memory"
	memory.Parent = StatsFolder
	
	local memorylevel = Instance.new("IntValue")
	memorylevel.Name = "MemoryLevel"
	memorylevel.Parent = StatsFolder
	
	local mouselevel = Instance.new("IntValue")
	mouselevel.Name = "MouseLevel"
	mouselevel.Parent = StatsFolder
	
	local rcamount = Instance.new("IntValue")
	rcamount.Name = "RCAmount"
	rcamount.Parent = StatsFolder
	
	local rcmultimoney = Instance.new("NumberValue")
	rcmultimoney.Name = "RCMultiMoney"
	rcmultimoney.Parent = StatsFolder
	
	local rcmulticlicks = Instance.new("NumberValue")
	rcmulticlicks.Name = "RCMultiClicks"
	rcmulticlicks.Parent = StatsFolder
	
	local rc1collected = Instance.new("BoolValue")
	rc1collected.Name = "RC1Col"
	rc1collected.Parent = StatsFolder
	
	local rc2collected = Instance.new("BoolValue")
	rc2collected.Name = "RC2Col"
	rc2collected.Parent = StatsFolder
	
	local moneyfromtrade = Instance.new("NumberValue")
	moneyfromtrade.Name = "MoneyFT"
	moneyfromtrade.Parent = StatsFolder
	
	local clicksperclick = Instance.new("NumberValue")
	clicksperclick.Name = "ClicksPerClick"
	clicksperclick.Parent = StatsFolder
	
	local leafstat = Instance.new("BoolValue")
	leafstat.Name = "LeafStat"
	leafstat.Parent = SecretStatsFolder
	
	local success, result = protectedCall(function()
		return dataStore:GetAsync("Data_"..player.UserId)
	end)

	if success then
		if result then
			if type(result) == "table" then
				clicks.Value = result[1] or 0
				money.Value = result[2] or 0
				rebirths.Value = result[3] or 0
				memory.Value = result[4] or 10
				memorylevel.Value = result[5] or 0
				mouselevel.Value = result[6] or 0
				rcamount.Value = result[7] or 0
				rcmultimoney.Value = result[8] or 1
				rc1collected.Value = result[9] or false
				moneyfromtrade.Value = result[10] or 1
				rcmulticlicks.Value = result[11] or 1
				clicksperclick.Value = result[12] or 1
				rc2collected.Value = result[13] or false
				leafstat.Value = result[14] or false
			end
		end
	else
		warn(result)
	end
end

local function onPlayerLeft(player)
	local success, result = protectedCall(function()
		return dataStore:SetAsync("Data_"..player.UserId, {player.leaderstats.Clicks.Value, player.leaderstats.Money.Value, player.leaderstats.Rebirths.Value, player.Stats.Memory.Value, player.Stats.MemoryLevel.Value, player.Stats.MouseLevel.Value, player.Stats.RCAmount.Value, player.Stats.RCMultiMoney.Value, player.Stats.RC1Col.Value,player.Stats.MoneyFT.Value, player.Stats.RCMultiClicks.Value, player.Stats.ClicksPerClick.Value, player.Stats.RC2Col.Value, player.SecretStats.LeafStat.Value})
	end)

	if success then
		print(result)
		print("Everything success")
	else
		warn(result)
		warn("everything wrong")
	end
end

local function onServerClosed()
	for _, player in ipairs(playersService:GetPlayers()) do
		local success, result = protectedCall(function()
			return dataStore:SetAsync("Data_"..player.UserId, {player.leaderstats.Clicks.Value, player.leaderstats.Money.Value, player.leaderstats.Rebirths.Value, player.Stats.Memory.Value, player.Stats.MemoryLevel.Value, player.Stats.MouseLevel.Value, player.Stats.RCAmount.Value, player.Stats.RCMultiMoney.Value, player.Stats.RC1Col.Value,player.Stats.MoneyFT.Value, player.Stats.RCMultiClicks.Value, player.Stats.ClicksPerClick.Value, player.Stats.RC2Col.Value, player.SecretStats.LeafStat.Value})
		end)

		if success then
			print(result)
		else
			warn(result)
		end
	end
end

playersService.PlayerAdded:Connect(onPlayerJoined)
playersService.PlayerRemoving:Connect(onPlayerLeft)
game:BindToClose(onServerClosed) 

Normally get the datastore as if you were doing it in another script from the same game.

Like that?
Boss place:

local playersService = game:GetService("Players")
local dataStores = game:GetService("DataStoreService")
local dataStore = dataStores:GetDataStore("DataStore")

local protectedCall = pcall

local function onPlayerJoined(player)
	local SecretStatsFolder = Instance.new("Folder")
	SecretStatsFolder.Name = "SecretStats"
	SecretStatsFolder.Parent = player
	
	local LeafStat = Instance.new("BoolValue")
	LeafStat.Name = "LeafStat"
	LeafStat.Parent = SecretStatsFolder
	local success, result = protectedCall(function()
		return dataStore:GetAsync("Data_"..player.UserId)
	end)

	if success then
		if result then
			if type(result) == "table" then
			LeafStat.Value = result[1] or false
			end
		end
	else
		warn(result)
	end
end

local function onPlayerLeft(player)
	local success, result = protectedCall(function()
		return dataStore:SetAsync("Data_"..player.UserId, {player.SecretStatsFolder.LeafStat.Value})
	end)

	if success then
		print(result)
		print("Everything success")
	else
		warn(result)
		warn("everything wrong")
	end
end

local function onServerClosed()
	for _, player in ipairs(playersService:GetPlayers()) do
		local success, result = protectedCall(function()
			return dataStore:SetAsync("Data_"..player.UserId, {player.SecretStatsFolder.LeafStat.Value})
		end)

		if success then
			print(result)
		else
			warn(result)
		end
	end
end

playersService.PlayerAdded:Connect(onPlayerJoined)
playersService.PlayerRemoving:Connect(onPlayerLeft)
game:BindToClose(onServerClosed) 

Main place:

local playersService = game:GetService("Players")
local dataStores = game:GetService("DataStoreService")
local dataStore = dataStores:GetDataStore("DataStore")

local protectedCall = pcall

local function onPlayerJoined(player)
	local StatsFolder = Instance.new("Folder")
	StatsFolder.Name = "Stats"
	StatsFolder.Parent = player
	
	local SecretStatsFolder = Instance.new("Folder")
	SecretStatsFolder.Name = "SecretStats"
	SecretStatsFolder.Parent = player
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local clicks = Instance.new("IntValue")
	clicks.Name = "Clicks"
	clicks.Parent = leaderstats

	local money = Instance.new("NumberValue")
	money.Name = "Money"
	money.Parent = leaderstats

	local rebirths = Instance.new("IntValue")
	rebirths.Name = "Rebirths"
	rebirths.Parent = leaderstats
	
	local memory = Instance.new("IntValue")
	memory.Name = "Memory"
	memory.Parent = StatsFolder
	
	local memorylevel = Instance.new("IntValue")
	memorylevel.Name = "MemoryLevel"
	memorylevel.Parent = StatsFolder
	
	local mouselevel = Instance.new("IntValue")
	mouselevel.Name = "MouseLevel"
	mouselevel.Parent = StatsFolder
	
	local rcamount = Instance.new("IntValue")
	rcamount.Name = "RCAmount"
	rcamount.Parent = StatsFolder
	
	local rcmultimoney = Instance.new("NumberValue")
	rcmultimoney.Name = "RCMultiMoney"
	rcmultimoney.Parent = StatsFolder
	
	local rcmulticlicks = Instance.new("NumberValue")
	rcmulticlicks.Name = "RCMultiClicks"
	rcmulticlicks.Parent = StatsFolder
	
	local rc1collected = Instance.new("BoolValue")
	rc1collected.Name = "RC1Col"
	rc1collected.Parent = StatsFolder
	
	local rc2collected = Instance.new("BoolValue")
	rc2collected.Name = "RC2Col"
	rc2collected.Parent = StatsFolder
	
	local moneyfromtrade = Instance.new("NumberValue")
	moneyfromtrade.Name = "MoneyFT"
	moneyfromtrade.Parent = StatsFolder
	
	local clicksperclick = Instance.new("NumberValue")
	clicksperclick.Name = "ClicksPerClick"
	clicksperclick.Parent = StatsFolder
	
	local leafstat = Instance.new("BoolValue") -- leaf boss
	leafstat.Name = "LeafStat"
	leafstat.Parent = SecretStatsFolder
	
	local success, result = protectedCall(function()
		return dataStore:GetAsync("Data_"..player.UserId)
	end)

	if success then
		if result then
			if type(result) == "table" then
				clicks.Value = result[1] or 0
				money.Value = result[2] or 0
				rebirths.Value = result[3] or 0
				memory.Value = result[4] or 10
				memorylevel.Value = result[5] or 0
				mouselevel.Value = result[6] or 0
				rcamount.Value = result[7] or 0
				rcmultimoney.Value = result[8] or 1
				rc1collected.Value = result[9] or false
				moneyfromtrade.Value = result[10] or 1
				rcmulticlicks.Value = result[11] or 1
				clicksperclick.Value = result[12] or 1
				rc2collected.Value = result[13] or false
				leafstat.Value = result[14] or false
			end
		end
	else
		warn(result)
	end
end

local function onPlayerLeft(player)
	local success, result = protectedCall(function()
		return dataStore:SetAsync("Data_"..player.UserId, {player.leaderstats.Clicks.Value, player.leaderstats.Money.Value, player.leaderstats.Rebirths.Value, player.Stats.Memory.Value, player.Stats.MemoryLevel.Value, player.Stats.MouseLevel.Value, player.Stats.RCAmount.Value, player.Stats.RCMultiMoney.Value, player.Stats.RC1Col.Value,player.Stats.MoneyFT.Value, player.Stats.RCMultiClicks.Value, player.Stats.ClicksPerClick.Value, player.Stats.RC2Col.Value, player.SecretStats.LeafStat.Value})
	end)

	if success then
		print(result)
		print("Everything success")
	else
		warn(result)
		warn("everything wrong")
	end
end

local function onServerClosed()
	for _, player in ipairs(playersService:GetPlayers()) do
		local success, result = protectedCall(function()
			return dataStore:SetAsync("Data_"..player.UserId, {player.leaderstats.Clicks.Value, player.leaderstats.Money.Value, player.leaderstats.Rebirths.Value, player.Stats.Memory.Value, player.Stats.MemoryLevel.Value, player.Stats.MouseLevel.Value, player.Stats.RCAmount.Value, player.Stats.RCMultiMoney.Value, player.Stats.RC1Col.Value,player.Stats.MoneyFT.Value, player.Stats.RCMultiClicks.Value, player.Stats.ClicksPerClick.Value, player.Stats.RC2Col.Value, player.SecretStats.LeafStat.Value})
		end)

		if success then
			print(result)
		else
			warn(result)
		end
	end
end

playersService.PlayerAdded:Connect(onPlayerJoined)
playersService.PlayerRemoving:Connect(onPlayerLeft)
game:BindToClose(onServerClosed) 

Okay i made SAME datastores and folders, but i can’t share across one game places. I do not understand which line i need to add

This just do not work, could someone explain which line i should add to make it work

I made everything same except table result bcz in boss place leaf stat table is result[1] and in main game result[13]

Don’t make it complicated, just re-call the datastore with the code above in any server script you need. (as long as all places are in the same universe.)

Every datastore is saved in a table, and i still do not understand how to access that value from main game script

Omg everyone say that easy, but no one can’t give me an solution bcz I DO NOT KNOW WHICH LINE I SHOULD ADD TO MY DATASOTORE SCRIPT TO GET THAT VALUE