Double is not allowed in datastores - Leaderboard problem

  1. What do you want to achieve?
    Basically currency leaderboard

  2. What is the issue?
    Too much decimals in value

  3. What solutions have you tried so far?
    I tried search for some solutions but didnt saw anything that could help me.

Lb script:

local ds = game:GetService("DataStoreService")
local M = require(game.ReplicatedStorage:WaitForChild("ModuleScript"))

local blocksODS = ds:GetOrderedDataStore("CurrencyStats1")


local timeUntilReset = 60

local function update()
	for i, plr in pairs(game.Players:GetPlayers()) do

		blocksODS:SetAsync(plr.UserId, plr.Stats.TotalCurrency.Value)
	end
	
	for i, leaderboardRank in pairs(script.Parent:GetChildren()) do

		if leaderboardRank.ClassName == "Frame" then
			leaderboardRank:Destroy()
		end
	end


	local success, errorMsg = pcall(function()

		local data = blocksODS:GetSortedAsync(false, 25)
		local blocksPage = data:GetCurrentPage()

		for rankInLB, dataStored in ipairs(blocksPage) do


			local name = game.Players:GetNameFromUserIdAsync(tonumber(dataStored.key))
			local blocks = dataStored.value
			local template = script.Template:Clone()
			template.Name = name .. "Leaderboard"
			template.PlrNameTemplate.PlrName.Text = name
			template.RankTemplate.Rank.Text = "#" .. rankInLB
			template.CurrencyTemplate.Blocks.Text = M.ZeroTwoIsCute(blocks)
			template.Parent = script.Parent		
		end
	end)		
end

while wait(1) do
	
	update()
	
	wait(60)
	
	spawn(function()
		
	timeUntilReset = timeUntilReset - 1
	
	script.Parent.Parent.ResetTime.Text = "Resetting in " .. timeUntilReset .. " seconds..."
	
	
	if timeUntilReset == 0 then
		
		timeUntilReset = 10
		
		end
	end)
end

Thank you guys for any solutions :)!

1 Like

This might help.

3 Likes

Multiply the value by 100000 when you save the value and divide it by 100000 when you get the saved value from datastore, that should stop the doubles

1 Like

Hey! Sorry for late response can you please show me example in my script because Im not that experienced in things like this :D. Thank you!

Nevermind got it thank you guys so much!

I am so sorry for reviving this post but something is not right when I had small number like 75.241 it worked fine but In my game I often get to value 75.2415687459718489 something like this basically and Error appear again any solution for that many decimals (25) as I counted in game?

local numberOfDecimalPlacesNeedToBeSaved = 6

local originalValue = 2342.523452345234523452345

local valueToSave = math.floor(originalValue * (10^numberOfDecimalPlacesNeedToBeSaved))

print(valueToSave)

-- ...

local yourLoadedValue = 2342523452

local parsedAndLoadedValue = yourLoadedValue / (10^numberOfDecimalPlacesNeedToBeSaved)

print(parsedAndLoadedValue)
2 Likes

Hey simply fixed by math.modf :pray:

This issue is already solved no need to revive this post again :smiley:.