DataStore Script for 5K

I am making a shop for my game that uses a DataStore system to save values.
I have a list of the needed values below. (They don’t need to be a leader board, but they need to be values inside the local player)

[code]local info = Instance.new(“StringValue”)
info.Name = “PlayerInfo”
info.Parent = player

local Diamonds = Instance.new("NumberValue")
Diamonds.Name = "Diamonds"
Diamonds.Parent = info
Diamonds.Value = DataStore:GetAsync(player.userId.."Diamonds") or 0

local Credits = Instance.new("NumberValue")
Credits.Name = "Credits"
Credits.Parent = info
Credits.Value = DataStore:GetAsync(player.userId.."Credits") or 0

local Doge = Instance.new("StringValue")
Doge.Name = "Doge"
Doge.Parent = info
Doge.Value = DataStore:GetAsync(player.userId.."Doge") or "false"

local Valk = Instance.new("StringValue")
Valk.Name = "Valk"
Valk.Parent = info
Valk.Value = DataStore:GetAsync(player.userId.."Valk") or "false"

local Messor = Instance.new("StringValue")
Messor.Name = "Messor"
Messor.Parent = info
Messor.Value = DataStore:GetAsync(player.userId.."Messor") or "false"

local Vesp = Instance.new("StringValue")
Vesp.Name = "Vesp"
Vesp.Parent = info
Vesp.Value = DataStore:GetAsync(player.userId.."Vesp") or "false"

local RedSparkle = Instance.new("StringValue")
RedSparkle.Name = "RedSparkle"
RedSparkle.Parent = info
RedSparkle.Value = DataStore:GetAsync(player.userId.."RedSparkle") or "false"

local Sini = Instance.new("StringValue")
Sini.Name = "Sini"
Sini.Parent = info
Sini.Value = DataStore:GetAsync(player.userId.."Sini") or "false"

local wtop = Instance.new("StringValue")
wtop.Name = "wtop"
wtop.Parent = info
wtop.Value = DataStore:GetAsync(player.userId.."wtop") or "false"

local musica = Instance.new("StringValue")
musica.Name = "musica"
musica.Parent = info
musica.Value = DataStore:GetAsync(player.userId.."musica") or "false"

local reddom = Instance.new("StringValue")
reddom.Name = "reddom"
reddom.Parent = info
reddom.Value = DataStore:GetAsync(player.userId.."reddom") or "false"

local rduck = Instance.new("StringValue")
rduck.Name = "rduck"
rduck.Parent = info
rduck.Value = DataStore:GetAsync(player.userId.."rdcuk") or "false"

local sttf = Instance.new("StringValue")
sttf.Name = "sttf"
sttf.Parent = info
sttf.Value = DataStore:GetAsync(player.userId.."sttf") or "false"

local Wconj = Instance.new("StringValue")
Wconj.Name = "Wconj"
Wconj.Parent = info
Wconj.Value = DataStore:GetAsync(player.userId.."Wconj") or "false"

local Lconj = Instance.new("StringValue")
Lconj.Name = "Lconj"
Lconj.Parent = info
Lconj.Value = DataStore:GetAsync(player.userId.."Lconj") or "false"

local kettle = Instance.new("StringValue")
kettle.Name = "kettle"
kettle.Parent = info
kettle.Value = DataStore:GetAsync(player.userId.."kettle") or "false"

local tpot = Instance.new("StringValue")
tpot.Name = "tpot"
tpot.Parent = info
tpot.Value = DataStore:GetAsync(player.userId.."tpot") or "false"

local NextLogin = Instance.new("NumberValue")
NextLogin.Name = "NextLogin"
NextLogin.Value = DataStore:GetAsync(player.userId.."NextLogin") or 0
NextLogin.Parent = info

local Time = os.time()
if NextLogin.Value <= Time then
	local NewGui = script.LoginGUI:Clone()
	NewGui.Parent = player:WaitForChild("PlayerGui")
	NewGui.GetDiamond.Disabled = false
	NextLogin.Value = Time + (12*60*60)
	DataStore:UpdateAsync(player.userId.."NextLogin" ,function() return NextLogin.Value end)
end

print('Success')
while true do
	local Time = os.time()
	if NextLogin.Value <= Time then
		local NewGui = script.LoginGUI:Clone()
		NewGui.Parent = player:WaitForChild("PlayerGui")
		NewGui.GetDiamond.Disabled = false
		NextLogin.Value = Time + (12*60*60)
		DataStore:UpdateAsync(player.userId.."NextLogin" ,function() return NextLogin.Value  end)
	end
	wait(1)
end

end)
[/code]

Dude, you can save a table in the datastore. You don’t need to make a separate request for every little thing.

Adding on to what Ethan stated:
DataStore is not like Data Persistence. There are lower limits, so each time you use SetAsync, GetAsync, UpdateAsync, etc…, you use up requests for each call. The methods for Data Persistence had to be called like this because it doesn’t allow different data types to be saved in the same key.

[quote] Adding on to what Ethan stated:
DataStore is not like Data Persistence. There are lower limits, so each time you use SetAsync, GetAsync, UpdateAsync, etc…, you use up requests for each call. The methods for Data Persistence had to be called like this because it doesn’t allow different data types to be saved in the same key. [/quote]

It did;

local RBXUtility = loadlibrary('RbxUtility')
game.Players.Player1:SaveString('data', RBXUtility.EncodeJSON{Score=1337, KOs = -1, WOs = -1, Name = "1337 h4x0r"})

But, it’s still definitely not the recommended way to store things. Use tables and DataStores. Or, if you want to be cool, use Stravant’s BitBuffer module to save your data in a small number of characters.

I don’t really understand datastores and my previous script i had broke. I just need there to be these values in a new working datastore or help with a new system.

Datastores are fundamental to game design.

You should probably take the time to learn them rather than paying someone else to do it, because you are certain to need them again should you make more games.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.