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

Why is my DataStore not functioning?

I have been working on a simulator game for quite a long time now, but I can not find out why the DataStore is not working. API services are on. Here is what I tried.

local ds = game:GetService("DataStoreService"):GetDataStore("SaveData")
game.Players.PlayerAdded:Connect(function(plr)
	wait()
	local plrkey = "id_"..plr.userId
	local save1 = plr.leaderstats.Strength
	local save2 = plr.leaderstats.Cash
	local save3 = plr.leaderstats.Rebirths
	
	local GetSaved = ds:GetAsync(plrkey)
	if GetSaved then
		save1.Value = GetSaved[1]
		save2.Value = GetSaved[2]
		save3.Value = GetSaved[3]
	else
		local NumberForSaving = {save1.Value, save2.Value, save3.Value}
		ds:GetAsync(plrkey, NumberForSaving)
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	ds:SetAsync("id_"..plr.userId {plr.leaderstats.Strength.Value, plr.leaderstats.Cash.Value, plr.leaderstats.Rebirths.Value})
end)

here are the leaderstats:

game.Players.PlayerAdded:Connect(function(player)
	local stats = Instance.new("Folder")
	stats.Name = "leaderstats"
	stats.Parent = player
	
	local strength = Instance.new("IntValue")
	strength.Name = "Strength"
	strength.Value = 0 
	strength.Parent = stats
	
	local cash = Instance.new("IntValue")
	cash.Name = "Cash"
	cash.Value = 0
	cash.Parent = stats
	
	local rebirths = Instance.new("IntValue")
	rebirths.Name = "Rebirths"
	rebirths.Value = 0
	rebirths.Parent = stats
end)

1 answer

✓ Accepted answer
ds:SetAsync("id_"..plr.userId, {plr.leaderstats.Strength.Value...

missing a comma

1 comment

0

@megukoo LOL tysm I was confused for hours because of the missing comma

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