Datastore not saving across multiple places

Hello Roblox Dev Community,

Info
So i have created a datastore for 2 places.
The 2 places are inside of the same game (like the same Universe).

Experience > PlaceA/PlaceB

Also in this post there stands that datastore should be possible of transferring without any different adjustments: How to make DataStores sync over multiple places in the same game?

Datastore Script
local dataStoreService = game:GetService("DataStoreService")
local datastore = dataStoreService:GetDataStore("DatastoreMainandEquippedStuffTable", nil)

local plrs = game:GetService("Players")

local runService = game:GetService("RunService")

local function saveData(plr)
	if not runService:IsRunMode() then
		wait(1)
		local plrData = plr.PlayerData
		local plrLeaderstats = plr:WaitForChild("leaderstats")
		local plrSouls = plrLeaderstats.Souls
		local plrTime = plrData.TimePlayed

		local plrEquippedCurse = plr.EquippedCurse
		local plrEquippedGuardian = plr.EquippedGuardian
		local plrEquippedNametag = plr.EquippedNametag

		local mainStuffTable = {
			plrSouls.Value,
			plrTime.Value
		}

		local equippedStuffTable = {
			plrEquippedCurse.Value,
			plrEquippedGuardian.Value,
			plrEquippedNametag.Value
		}

		local success, notSuccess = pcall(function()
			datastore:SetAsync(plr.UserId.."-MainStuff", mainStuffTable)
		end)

		local success2, notSuccess2 = pcall(function()
			datastore:SetAsync(plr.UserId.."-EquippedStuff", equippedStuffTable)
		end)

		if not success then
			warn(notSuccess)
		end

		if not success2 then
			warn(notSuccess2)
		end
	end
end

local function importData(plr)
	if not runService:IsRunMode() then
		wait(1)
		local plrData = plr.PlayerData
		local plrLeaderstats = plr:WaitForChild("leaderstats")
		local plrSouls = plrLeaderstats.Souls
		local plrTime = plrData.TimePlayed

		local plrEquippedCurse = plr.EquippedCurse
		local plrEquippedGuardian = plr.EquippedGuardian
		local plrEquippedNametag = plr.EquippedNametag

		local data
		local working, notWorking = pcall(function()
			data = datastore:GetAsync(plr.UserId.."-MainStuff")
		end)

		local data2
		local working2, notWorking2 = pcall(function()
			data2 = datastore:GetAsync(plr.UserId.."-EquippedStuff")
		end)

		if working and data ~= nil then
			plrSouls.Value = data[1]
			plrTime.Value = data[2]
		else
			warn(notWorking)
		end

		if working2 and data ~= nil then
			plrEquippedCurse.Value = data2[1]
			plrEquippedGuardian.Value = data2[2]
			plrEquippedNametag.Value = data2[3]
		else
			warn(notWorking)
		end
	end
end

function playerAdded(plr)
	script.leaderstats:Clone().Parent = plr
	script.PlayerData:Clone().Parent = plr
	script.EquippedCurse:Clone().Parent = plr
	script.EquippedGuardian:Clone().Parent = plr
	script.EquippedNametag:Clone().Parent = plr

	importData(plr)

	while wait(60) do
		plr.PlayerData.TimePlayed.Value += 1
	end
end

function playerLeft(plr)
	local success, notSuccess = pcall(function()
		wait(1)
		saveData(plr)
	end)

	if not success then
		warn(notSuccess)
	end
end

game:BindToClose(function()
	wait(2)
end)

plrs.PlayerAdded:Connect(playerAdded)
plrs.PlayerRemoving:Connect(playerLeft)

The same datastore is used for both places, but the problem is that it only saves it for that place.

Datastore Script in Explorer

image

Game Settings - Security Tab

Demonstration
So if i would to join the game with 10 souls (currency) in placeA and then buy something and then have 7 souls (currency) left, and rejoin. I would still have 7 souls (currency) left, but if i would join placeB trough a ingame teleported, i would have 0 souls (currency). If i would have 43 souls (currency) in placeB and then go trough the teleporter to placeA i would still have 7 souls (currency)

The script is a Server Script inside of ServerScriptService

If anyone knows anything about this, it would be very appreciated because we wanted to release the game soon. Already, thank you very much.

Have a good day, cya!
:waffle: :wave:

1 Like

From memory I believe you need to send the data to the other place, they might have to communicate with each other not entirelly sure.

Also, I don’t think this is the issue, but it is currently Impossible to transmit data from one unrelated place to another, they both have to be in the same universe. (If you know what that means).

With that said, try searching for “Roblox Studio how to save data through multiple places/universe”.
This may also help, and check this too.

1 Like

I got them both in the same universe as ur saying, the 2 places are the same Experience but a different place. Got it? I am also gonna try ur solutions :). Here is the link where i found that my script should be working:

Anyone got any other ideas or observations?

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