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

data store script aint working. i neeed help ?

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

✓ Accepted answer

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.

1 comment

0

sorry for the "*" in the first line of code, i didnt mean to put that there

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