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

Datastores Across Universe?

I've been working on my project, and it uses DataStores across a universe.

Here is script one

local datastore = game:GetService("DataStoreService"):GetDataStore("Vestige")

game.Players.PlayerRemoving:connect(function(leavingplayer)
	wait(2)
	local stats = leavingplayer:FindFirstChild("Statistics"):GetChildren()
	for x = 1,#stats do
		print(stats[x].Name)
	end
end)

game.Players.PlayerAdded:connect(function(player)
	wait(2)
	local newstats = player:FindFirstChild("Statistics"):GetChildren()
	for x = 1, #newstats do
		newstats[x].Value = datastore:GetAsync(newstats[x].Name)
	end
end)

Here is the script in the other place in the universe

local datastore = game:GetService("DataStoreService"):GetDataStore("Vestige")

script.Parent.MouseClick:connect(function(plr) 
	if plr.PlayerGui:findFirstChild("ScreenGui") then
		print("already clicked")
	else
		local cl = script.Parent.ScreenGui:Clone()
		cl.Parent = plr.PlayerGui
		game.Players.PlayerRemoving:connect(function(leavingplayer)
			leavingplayer.Statistics.Coins = leavingplayer.Statistics.Coins + 10
			wait(2)
			local stats = leavingplayer:FindFirstChild("Statistics"):GetChildren()
			for x = 1,#stats do
				print(stats[x].Name)
			end
		end)
	end
end)

The GUI part of the second script works, but it doesn't add any more coins. Could anyone help?

2 comments

0

What is the problem exactly?

0

It doesn't save the coins. You're meant to get coins in one place, and they save into the statistics folder on the next place.

1 answer

Try removing the wait(2)s. Its possible that due to the player leaving, the player leaves before the data can be saved.

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