Data doesn't save string values

Hey, I’m trying to make a game where I bypass the 1.72e308 limit so I use EternityNum.
The problem is that my data doesn’t save a string value but I have an other stat which is a number value and it saves perfectly.
I have no errors in the output tho.
Here is my data script:

local EN = require(game.ReplicatedStorage.EternityNum)
local Data = game:GetService("DataStoreService"):GetDataStore("Data")

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

	local Rarity = Instance.new("NumberValue", leaderstats)
	Rarity.Name = "Rarity"
	Rarity.Value = 1

	local luck = Instance.new("StringValue", leaderstats)
	luck.Name = "Luck"
	luck.Value = "1"

	local dataload = Data:GetAsync(tostring(plr.UserId))

	if dataload then
		Rarity.Value = dataload[1]
		luck.Value = dataload[2]
	else
		Rarity.Value = 1
		luck.Value = "1"
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	Data:SetAsync(tostring(plr.UserId),{
		plr.leaderstats.Rarity.Value,
		tostring(plr.leaderstats.Luck.Value)
	})
end)

Here is a video of me rejoining the game, and you can see that “Rarity” saved but “Luck” (which is a string) didn’t.

Try turning off the script that changes the value every millisecond

1 Like

The script that changes values will overwrite the loaded data,
also try printing the data when it loads.

Just do:

print(dataload)

First of all, I recommend that you use pcall() so that if it errors, you know the error and script would run smoothly.

Secondly, there isn’t any actual error. When you’re showing us the “Luck” value is 1, it is actually the time when DataStore didn’t load. If you think logically, code takes time to run. Similar logic, DataStores take time to load. And when it loads, your random string generator starts. As @drkica1234 said, try disabling it for a moment and then tell us.

1 Like

Hey, thanks for reaching out to me.
I used pcall() for my data, and I got no errors.
As @drkica1234 said, I changed the script that changes the value every millisecond to something way slower and added a WaitForChild to be sure that the data loads before the script is running.
Even after doing this, nothing happened. When I rejoined 2 minutes after, my “Luck” was reset to 1 but my rarity kept the same value.
When I completely removed the script that changes the value, the data saved tho. Here is the script:

local EN = require(game.ReplicatedStorage.EternityNum)

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = player:WaitForChild("leaderstats")
	local luck = leaderstats:WaitForChild("Luck")
	local L = EN.fromString(luck.Value)
	while wait(1) do
		L = EN.mul(L, 100)
		luck.Value = EN.short(L)
	end
end)

I now know that the problem comes from there but I don’t see any errors…

Btw, if someone wants the EternityNum module I use, here it is: EternityNum 2 - Roblox

String values take time to save. That’s why you need a BindToClose for it.

I found the issue. My scripts didn’t have enough time to find the data so it caused a bug. I simply added a wait function and it solved it.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.