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

data store script aint working. i neeed help ?

Asked by 2 years ago

well my script is for a clicking sim and i am trying to save my leadersats!

local ds = game:GetService("DataStoreService"):GetDataStore("LeaderBoardSave")

game.Players.PlayerAdded:Connect(function(player) local folder = Instance.new("Folder", player) folder.Name = "leaderstats"

local val = Instance.new("IntValue")
val.Name = "Clicks"
val.Value = 0
val.Parent = player.leaderstats

local val2 = Instance.new("IntValue")
val2.Name = "Rebirths"
val2.Value = 0
val2.Parent = player.leaderstats

local val3 = Instance.new("IntValue")
val3.Name = "Coins"
val3.Value = 0
val3.Parent = player.leaderstats

local val4 = Instance.new("IntValue")
val4.Name = "Gems"
val4.Value = 0
val4.Parent = player.leaderstats

local stats = ds:GetAsync(player.UserId)


if stats ~= nil then
    val.Value = stats[1]
    val2.Value = stats[2]
    val3.Value = stats[3]
    val4.Value = stats[4]
else
    val.Value = 0
    val2.Value = 0
    val3.Value = 0
    val4.Value = 0
end

end)

game.Players.PlayerRemoving:Connect(function(player) local save = {}

table:insert(save, player.leaderstats.Clicks.Value)
table:insert(save, player.leaderstats.Rebirths.Value)
table:insert(save, player.leaderstats.Coins.Value)
table:insert(save, player.leaderstats.Gems.Value)

ds:SetAsync(player.UserId, save)

end)

game:BindToClose(function() wait(1.25) end)``

1 answer

Log in to vote
0
Answered by 2 years ago

Well for leaderstats i wouldnt use a table, i prefer to save it to multiple asyncs. A SaveAsync uses first the "key" to the information. The key is what will have to be used by the GetAsync in order to load the data. So say for example saving your rebirths would go as follows:

LeaderBoardSave:SetAsync(Player.UserId"-rebirths", *Player.Leaderstats.Rebirths.Value)

just remember this isnt eactly for your game, but it should give you a good guideline to go off of. Getting the Async for your rebirths would go like this:

RebirthsData = LeaderBoardSave:GetAsync(Player.UserId.."-Rebirths")

when you want to set the value just type:

Player.Leaderstats.Rebirths.Value = RebirthsData

I hope this helps, and also you will have to do this for each value. This is the only way i know to save data.

0
sorry for the "*" in the first line of code, i didnt mean to put that there Verse_NOVA 52 — 2y
Ad

Answer this question