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

Why isn't datastore saving the money value?

Asked by 5 years ago

Ok so I made this script that makes you save your values when you leave using datastore theres 2 values but one called "Money" won't save

I am also using a sell script that turns your wood into money idk but i think it might have to do with something in saving

game.Players.ChildAdded:connect(function(Player)

local Lead = Instance.new("IntValue",Player)

Lead.Name = "leaderstats"

local Cash = Instance.new("IntValue",Lead)

Cash.Name = "Wood"

Cash.Value = 0

local Cash2 = Instance.new("IntValue",Lead)

Cash2.Name = "Money"

Cash2.Value = 0

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

local Key = Player.userId

local Data = DataStore:GetAsync(Key)

if Data then

Cash.Value = Data

end

end)



game.Players.ChildRemoved:connect(function(Player)

local Key = Player.userId

DataStore:SetAsync(Key,Player.leaderstats.Wood.Value)

DataStore:SetAsync(Key,Player.leaderstats.Money.Value)

end)

When I leave it says this:

DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 46681528

1 answer

Log in to vote
1
Answered by
birds3345 177
5 years ago

DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 46681528 means you are sending to many requests, and for the part were you said "ChildRemoved" you should just use game.Players.PlayerRemoved:Connect(function() end) Also if you need it here is the code I wrote for you you can use it :)

local DS = game:GetService("DataStoreService"):GetDataStore("SavingSystem")

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

wait()

local plrkey = "id_"..plr.userId

local savevalue1 = plr:WaitForChild("leaderstats"):WaitForChild("Money")

local GetSaved = DS:GetAsync(plrkey)

if GetSaved then

savevalue1.Value = GetSaved[1]

else

local NumbersForSaving = {savevalue1.Value}

DS:GetAsync(plrkey, NumbersForSaving)

end

end)

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

DS:SetAsync("id_"..plr.userId, {plr.leaderstats.Money.Value})

end)
Ad

Answer this question