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
problem: you are using Data Persistance
the problems this creates:
the data only stays in that game
Data Persistance
is less reliable thanData 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
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.