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

There is a problem with my data store not saving data. Can anyone help?

I'm unsure about whats happening. One second my data store was working and now its not. If anyone knows whats wrong and can help me that would be great.

local Data = game:GetService("DataStoreService"):GetDataStore("CashData")

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

local folder = Instance.new("Folder", plr)

folder.Name = plr.Name

local cash = Instance.new("IntValue",folder)

cash.Name = "Cash"

local income = Instance.new("IntValue",folder)

income.Name = "Income"

local SavedItems = Data:GetAsync(plr.UserId)

if SavedItems then

cash.Value = SavedItems.Cash

else

cash.Value = 0

end

end)

  

game.Players.PlayerRemoving:Connect(function(plr)

local saving = {["Cash"] = plr:FindFirstChild(plr.Name).Cash.Value}

Data:SetAsync(plr.userId,saving)

end)

1 comment

0

By the way. I don't want income saving. I only want cash saving.

2 answers

try this:


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

local folder = Instance.new("Folder", plr)

folder.Name = plr.Name

local cash = Instance.new("IntValue",folder)

cash.Name = "Cash"

local income = Instance.new("IntValue",folder)

income.Name = "Income"

local SavedItems = Data:GetAsync(plr.UserId) or 0

if SavedItems then

cash.Value = SavedItems.Cash

else

cash.Value = 0

end

end)

  

game.Players.PlayerRemoving:Connect(function(plr)

local saving = {["Cash"] = plr:FindFirstChild(plr.Name).Cash.Value}

Data:SetAsync(plr.userId,saving)

end)```

1 comment

0

oh wait, be sure you turn on API Service

could it be syntax error?

my code usually looks like this:

saving = {Cash = plr:FindFirstChild(plr.Name).Cash.Value}

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