Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 5 years ago

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)
0
By the way. I don't want income saving. I only want cash saving. IcyBlazeRB 28 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

try this:

```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) 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)```

0
oh wait, be sure you turn on API Service Realdava 2 — 5y
Ad
Log in to vote
0
Answered by
Kami_Yo 72
5 years ago
Edited 5 years ago

could it be syntax error?

my code usually looks like this:

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

Answer this question