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

my leaderboard stats won't save?

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)

1 comment

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.

1 answer

✓ Accepted answer

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)

5 comments

0

thanks

0

um, if that changes too quickly, the requests will be throttled

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.

0

Never save each time the value changes. That is prone to request throttling.

0

I was just fixing up his script, not that I support saving every change.

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