Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to save data between places?

Asked by 8 years ago

Hello, nice to see you there! I am struggling to make and find a script that will save my leaderboard stats, as well has my inventory. The concept is that after each stage, it teleports you to a new game, with all your data. Is there any way i can do this? I tried many ways, but they were unsuccessful.

function onPlayerEntered(player)
wait()
player:WaitForDataReady()
repeat wait() until player:FindFirstChild("leaderstats")
if player.DataReady then
if player:findFirstChild("leaderstats") then
local score = player.leaderstats:GetChildren() 
for i = 1,#score do
local ScoreLoaded = player:LoadNumber(score[i].Name)
wait() 
if ScoreLoaded ~= 0 then
score[i].Value = ScoreLoaded
end
end
end
end
end

function onPlayerLeaving(player)
if player:findFirstChild("leaderstats") then
local score = player.leaderstats:GetChildren() 
for i = 1,#score do
player:SaveNumber(score[i].Name,score[i].Value)
end
end
end

if game.PlaceId == "224872882" or "224872666" then
    ScoreLoad = true
end

game.Players.PlayerAdded:connect(onPlayerEntered)
game.Players.PlayerRemoving:connect(onPlayerLeaving)

Thanks, Cake

0
Indent pls XD SynphonyKnight 85 — 8y

2 answers

Log in to vote
1
Answered by
lukeb50 631 Moderation Voter
8 years ago

problem: you are using Data Persistance the problems this creates:

the data only stays in that game

Data Persistance is less reliable than Data Stores

the solution would be to use Data Stores

the advantages of Data Stores:

data transfers between all games in a universe

reliable

store tables

some documentation

Core API: http://wiki.roblox.com/index.php?title=API:Class/DataStoreService

Tutorial: http://wiki.roblox.com/index.php?title=Data_store

Universes: http://wiki.roblox.com/index.php?title=Game

Ad
Log in to vote
0
Answered by 8 years ago

Before I start, I see you're using the outdated and unreliable DataPersistence. Stop. There is a new method, DataStores. DataStores are much more reliable and also work with Universes, something that I assume your game is using.

Now, you don't need to save data for this, rather transfer data.

When you teleport the player using a Teleport method, supply a variable known as teleport data. Send over the required data within an array, and let the other server use it!

If you're looking for a long-term solution, use DataStores.

Answer this question