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

Saving Items/Stats Between Games?

I was wondering if it was possible to transfer the data of your leaderstats to another game. For example, getting level 50 in a place and then teleporting to another and keeping your level.

I was also wondering if you could save the tools a player has between games. For example, getting a sword in a place then when you teleport to the new game you keep that sword.

I am not requesting but I am just wondering if somebody could point me in the right direction to doing this.

Thank you in advance,

2 answers

✓ Accepted answer

I believe this way to do it works:

You will need to go into your main game, and go to studio. Open the game explorer, and right click on the places folder. Then add a new place from there.

I believe you will be able to reference the same data store in that new place you just created.

Data stored within a datastore transfer between places. However, it does not transfer between different universes. If you want someone to have a sword within two completely different games, you'd have to use an external database.

If you just want to have a sword within two different places in a universe, then you'd have to save the sword's ID via a Datastore's GetAsync and SetAsync methods:

Players.PlayerAdded:Connect(function(player)
	local id = tostring(player.UserId);
	local attempts = 5;
	local data;
	repeat
		_, data = pcall(function()
			return DataStore:GetAsync(id) or {};
		end)
		attempts = attempts - 1;
	until data or (attempts <= 0);

	data = data or player:Kick("Data failed to load. Please try again later.");

	if (data.Sword) then Sword:Clone().Parent = player.StarterGear end;
end);
Players.PlayerRemoving:Connect(function(player)
	local id = tostring(player.UserId);
	pcall(function()
		return DataStore:SetAsync(id, {Sword = player.StarterGear:FindFirstChild('Sword') and true});
	end);
end);

..Something like that. Cheers.

1 comment

0

Both of your answers were very helpful. Thanks for the information and I will plan to use it in the future.

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