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

my datastore is still not working with filtering enabled. can any of you guys help me out here?

Asked by 5 years ago

I also wanted to let you that that FE is on and the script is in the workspace

local DSService = game:GetService("DataStoreService"):GetDataStore("Currency")

game:GetService("Players").PlayerAdded:connect(function(plr)
    local leader = Instance.new("Folder",plr)
    leader.Name = "leaderstats"

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

    local Diamonds = Instance.new("IntValue",leader)
    Diamonds.Name = "Diamonds"

    local savedData = DSService:GetAsync(plr.UserId.."-Currency")

    if savedData then
      Credits.Value = savedData[1]
      Diamonds.Value = savedData[2]
    else
      local values = {Credits.Value, Diamonds.Value}
      DSService:SetAsync(plr.UserId.."-Currency",values)
    end
end)

game:GetService("Players").PlayerRemoving:connect(function(plr)
    local ValuesToSave = {plr.leaderstats.Credits.Value, plr.leaderstats.Diamonds.Value}
    DSService:SetAsync(plr.UserId.."-Currency", ValuesToSave)
end)

while wait(300) do
    for i,v in pairs(game:GetService("Players"):GetChildren()) do
        DSService:UpdateAsync(v.UserId,v.leaderstats.Credits.Value,v.leaderstats.Diamonds.Value)
    end
end
0
What’s the issue? I don’t have a computer to find errors at the moment. T1mes 230 — 5y
0
How are you changing the values? arshad145 392 — 5y
0
I already tested your script , it works fine... workspace > Script ( Above content ) Press F9 > Server log then game.Players.NAMEHERE.leaderstats.Diamonds.Value = 9999. arshad145 392 — 5y

1 answer

Log in to vote
0
Answered by
hudzell 238 Moderation Voter
5 years ago

The server is shutting down before the data saves. To prevent this, you need to add game:BindToClose() to the script. Try this instead

local DSService = game:GetService("DataStoreService"):GetDataStore("Currency")
local Saving = 0

game:BindToClose(function()
    repeat wait() until Saving <= 0
end)

game:GetService("Players").PlayerAdded:connect(function(plr)
    local leader = Instance.new("Folder",plr)
    leader.Name = "leaderstats"

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

        local Diamonds = Instance.new("IntValue",leader)
        Diamonds.Name = "Diamonds"

    local savedData = DSService:GetAsync(plr.UserId.."-Currency")

    if savedData then
        Credits.Value = savedData[1]
        Diamonds.Value = savedData[2]
    else
        local values = {Credits.Value, Diamonds.Value}
        DSService:SetAsync(plr.UserId.."-Currency",values)
    end
end)

game:GetService("Players").PlayerRemoving:connect(function(plr)
    Saving = Saving + 1
    local ValuesToSave = {plr.leaderstats.Credits.Value, plr.leaderstats.Diamonds.Value}
    DSService:SetAsync(plr.UserId.."-Currency", ValuesToSave)
    Saving = Saving - 1
end)

while wait(300) do
    for i,v in pairs(game:GetService("Players"):GetChildren()) do
        DSService:UpdateAsync(v.UserId,v.leaderstats.Credits.Value,v.leaderstats.Diamonds.Value)
    end
end
0
thanks jakebball2014 84 — 5y
0
it still only work's in studio jakebball2014 84 — 5y
0
even though the leaderboard shows that the value changed in roblox jakebball2014 84 — 5y
Ad

Answer this question