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

my leaderboard stats won't save?

Asked by 5 years ago
Edited 5 years ago

I'm trying to make a saving system but it won't save. I keep on getting this error: "SetAsync is not a valid member of IntValue"

Server Script (ServerScriptService)

--Varibles
local DataStore = game:GetService("DataStoreService")
local DataStoreoofs = DataStore:GetDataStore("SaveSystemoofs")
local DataStorerank = DataStore:GetDataStore("SaveSystemrank")

game.Players.PlayerAdded:Connect(function(player)
    --Create Leaderstats
    local LeaderStats = Instance.new("Folder", player)
    LeaderStats.Name = "leaderstats"
    --Create Values
    local oofs = Instance.new("IntValue", LeaderStats)
    oofs.Name = "OOFS"
    local rank = Instance.new("IntValue", LeaderStats)
    rank.Name = "RANK"

    --Quick Saves
    oofs.Value = DataStoreoofs:GetAsync(player.UserId) or 0
    oofs:SetAsync(player.UserId, oofs.Value)

    rank.Value = DataStorerank:GetAsync(player.UserId) or 0
    rank:SetAsync(player.UserId, rank.Value)

    --Values changed (save)
    oofs.Changed:Connect(function()
        DataStoreoofs:SetAsync(player.UserId, oofs.Value)
    end)

    rank.Changed:Connect(function()
        DataStorerank:SetAsync(player.UserId, rank.Value)
    end)
end)
0
On line 18 and 21 you are attempting to SetAsync on IntValues. Perhaps you meant to SetAsync to DataStoreoofs and DataStorerank, in which case this is a simple error in writing. SummerEquinox 643 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

This will work.

Furthurmore, you shouldn't save as you load, because if datastore takes too long to respond, the player looses their stats, I would say that you should use an autosaver that saves every 30 seconds to 2 minutes.

Also, saving everytime a value is changed is ALSO a bad idea. What if someone keeps "oofing" / resetting, like 10 times a minute, this will result in dataloss.

USE AN AUTOSAVER AND GET RID OF QUICK SAVES

--Varibles
local DataStore = game:GetService("DataStoreService")
local DataStoreoofs = DataStore:GetDataStore("SaveSystem_oofs")
local DataStorerank = DataStore:GetDataStore("SaveSystem_rank")

game.Players.PlayerAdded:Connect(function(player)
    --Create Leaderstats
    local LeaderStats = Instance.new("Folder", player)
    LeaderStats.Name = "leaderstats"
    --Create Values
    local oofs = Instance.new("IntValue", LeaderStats)
    oofs.Name = "OOFS"
    local rank = Instance.new("IntValue", LeaderStats)
    rank.Name = "RANK"

    --Quick Saves
    oofs.Value = DataStoreoofs:GetAsync(player.UserId) or 0
    DataStoreoofs:SetAsync(player.UserId, oofs.Value)

    rank.Value = DataStorerank:GetAsync(player.UserId) or 0
   DataStorerank:SetAsync(player.UserId, rank.Value)

    --Values changed (save)
    oofs.Changed:Connect(function()
        DataStoreoofs:SetAsync(player.UserId, oofs.Value)
    end)

    rank.Changed:Connect(function()
        DataStorerank:SetAsync(player.UserId, rank.Value)
    end)
end)

0
thanks retrobricks 162 — 5y
0
um, if that changes too quickly, the requests will be throttled theking48989987 2147 — 5y
0
Outside of saving on PlayerRemoving, autosaves should happen when something important happens to the statistic (IE currency is purchased or a backup needs to be made). Saving on an interval is risky. SummerEquinox 643 — 5y
0
Never save each time the value changes. That is prone to request throttling. User#19524 175 — 5y
0
I was just fixing up his script, not that I support saving every change. NeonProfile 111 — 5y
Ad

Answer this question