DataStore not working?

I’ve been having issues with my DataStore and I am not popping off any errors in output. Hoping someone can take a look and let me know what’s going on.

I have gone through the script and checked everything over, made edits, etc and to no avail.
After that, you should include more details if you have any. Try to make your topic as descriptive as

Blockquote
local Datastore = game:GetService(“DataStoreService”):GetDataStore(“DataStore”)

game.Players.PlayerAdded:Connect(function(player)

local Folder = Instance.new("Folder", player)
Folder.Name = "StatData"

local Credits = Instance.new("IntValue", Folder)
Credits.Name = "cR"

local CreditsBank = Instance.new("IntValue", Folder)
CreditsBank.Name = "cRBank"

local Rock = Instance.new("IntValue", Folder)
Rock.Name = "Ore"

local Iron = Instance.new("IntValue", Rock)
Iron.Name = "Iron"

local Silicon = Instance.new("IntValue", Rock)
Silicon.Name = "Silicon"

local Nickel = Instance.new("IntValue", Rock)
Nickel.Name = "Nickel"

local Titanium = Instance.new("IntValue", Rock)
Titanium.Name = "Titanium"

local Platinum = Instance.new("IntValue", Rock)
Platinum.Name = "Platinum"

local Palladium = Instance.new("IntValue", Rock)
Palladium.Name = "Palladium"

local Phosphorus = Instance.new("IntValue", Rock)
Phosphorus.Name = "Phosphorus"


local ShipObject = Instance.new("ObjectValue", Folder)
ShipObject.Name = "Ship"


local Key = "User - " .. player.UserId

local storeditems = Datastore:GetAsync(Key)
if storeditems then
	Credits.Value = storeditems[1]
	CreditsBank.Value = storeditems[2]
	Rock.Value = storeditems[3]
else
	local Items = {Credits.Value, CreditsBank.Value, Rock.Value}
	Datastore:SetAsync(Key, Items)
end	

end)

game.Players.PlayerRemoving:Connect(function(player)
local Items = {player.StatData.cR.Value, player.StatData.cRBank.Value, player.StatData.Ore.Value}
local Key = “User-” … player.UserId
Datastore:SetAsync(Key, Items)
end)

Blockquote

3 Likes

either do wait for child for the local items or add Currency.Value for all of the currencies, or both. Hope this helps! :smiley:

2 Likes

Sorry, could you do me an Example?

2 Likes

Your datastore key is different, when you get the data it’s:

local Key = "User - " .. player.UserId

However when you save it on PlayerRemoving it’s:

local Key = "User-" … player.UserId

Even spaces in the key can prove a difference.

Also as Deferend spotted, you gotta remember to use .. instead of ... in your PlayerRemoving key.

2 Likes
local Silicon = Instance.new("IntValue", Rock)
Silicon.Name = "Silicon"
Silicon.Value == 0

local items = {player.Stats:WaitForChild("cR").Value

2 Likes

Also, ... is not a valid concatenation operator.

4 Likes

So much thanks guys, super appreciate it! :smiley:

3 Likes

Thought I should drop this in, since I see an abudance of cases where you’re using the parent argument of Instance.new: don’t do that. Especially not when you’re editing properties afterward.

2 Likes

Thank you! Fixed all my code with your advice.

1 Like