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

DataStore wipes when I update?

So whenever I update my game with this DataStore script it sets every player's stats back to the default they first had.

DataStore = game:GetService("DataStoreService"):GetDataStore("Values")


game.Players.PlayerAdded:connect(function(plr)
	local rank = Instance.new("StringValue", plr)
	rank.Value = "Asteroid Recruit"
	rank.Name = "Rank"
	
	local mined = Instance.new("IntValue", plr)
	mined.Value = 0
	mined.Name = "Mined"
	
	local save = "plr-"..plr.userId
	
	local savedVals = DataStore:GetAsync(save)
	
	if savedVals then
		rank.Value = savedVals[1]
		mined.Value = savedVals[2]
	else
		local val = {rank.Value, mined.Value}
		DataStore:SetAsync(save, val[1])
		DataStore:SetAsync(save, val[2])
	end
end)

game.Players.PlayerRemoving:connect(function(plr)
	local val = {plr.Rank.Value, plr.Mined.Value}
	local save = "plr-"..plr.userId
	DataStore:SetAsync(save, val[1])
	DataStore:SetAsync(save, val[2])
end)

And I don't know why

-- Any help is appreciated

1 answer

Are you saving tables? If you are, you should be using JSONEncode and JSONDecode. These are functions of HttpService, and they allow you to convert tables to strings, and JSON strings to tables.

First, make sure that HttpService is enabled. Then...

http = game:GetService("HttpService")

t = {
	Level = 1,
	Gold = 100
}

jt = http:JSONEncode(t)
print(jt)

And basically, you can use this to save JSON strings rather than tables.

1 comment

0

So what I should do is insert the values into a table and JSONEncode it? I don't understand JSONEncoding, I've never played with HTTPService

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