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

Multiple values saved using a single data store, Possible? (FE)

Hi guys, I'm trying to save a leaderstats with 2 values, here's my simple code:

ds = game:GetService("DataStoreService"):GetDataStore("DsName")  
PlayerStats = game:GetService("ServerStorage"):WaitForChild("PlayerStats") 

--Creating a leaderboard--
game.Players.PlayerAdded:connect(function(player)
	local key = player.UserId
	
	local playerfolder = Instance.new("Folder",player)      
	playerfolder.Name = "leaderstats"						
	
	local kill = Instance.new("IntValue", playerfolder)
	kill.Name = "kills"
	
	local point = Instance.new("IntValue", playerfolder)
	point.Name = "points"
	
	local asset = ds:GetAsync(key)      					

	if asset then
		kill.Value = asset[1]     --Error appear at this line.
		point.Value = asset[2]
		
	else
		local newleaderstats = {kill.Value, point.Value}
		ds:SetAsync(key, newleaderstats)
	end
end)

An error: "ServerScriptService.Script:51: attempt to index local 'asset' (a number value)" appeared at line 20 of my code. Was the error due to my datastore having only a single int value hence local asset is deemed as a variable and not an array? any idea what's wrong with it?

1 answer

✓ Accepted answer

It says your key retrieves a number value which maybe was an accident from old tests? Use a new datastore.

Also keys should be tostring(player.UserId) and you shouldn't SetAsync there if you end up doing saving later anyway.

2 comments

0

Ahh i see now, yeah that seemed to be the problem. Changing the key did the trick of eliminating the error. There isn't any way to reset datastore right? can't seem to find the old data using Datastore Editor

0

Like I said use like "DsName2" for a blank datastore its the same as a reset.

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