DataStore refuses to work in my game without releasing any sort of errors

The script:

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	local seconds = Instance.new("NumberValue", leaderstats)
	seconds.Name = "Seconds"
	seconds.Value = 0

	local success, data = pcall(function()
		return SecondsStore:GetAsync(player.UserId)
	end)

	if success and data then
		seconds.Value = data
	end

	if not success then
		warn("Failed to load data for player: " .. player.Name)
		seconds:Destroy()
		player:Kick("Failed to load your data. Try again later.")
	end

	while wait(1) do
		if seconds then
			seconds.Value = seconds.Value + 1
		end
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local success, errorMessage = pcall(function()
		SecondsStore:SetAsync(player.UserId, player.leaderstats.Seconds.Value)
	end)

	if not success then
		warn("Failed to save data for player: " .. player.Name .. ". Error: " .. errorMessage)
	end

	local Success,errormessage = pcall(function()
		badgeService:AwardBadge(player.UserId,276473952825522)
	end)

	if not Success then
		warn("Failed to award badge for player: " .. player.Name .. ". Error: " .. errormessage)
	end
end)

System Information:
Windows 11 Pro

The variables

local DatastoreService = game:GetService("DataStoreService")
local SecondsStore = DatastoreService:GetOrderedDataStore("PlayerSeconds")
local badgeService = game:GetService("BadgeService")

PlayerAdded is not guaranteed to be called, especially in Studio. You need to also loop through Players:GetChildren() and fire your PlayerAdded code for the players it fines. I would put this right after you hook up your PlayerAdded and PlayerRemove connections

the weird point is my public game and my studio version are both affected. player added is working since the seconds variable is created but doesnt load datastore without any sort of errors.

Hi, which DataStores call seems like its not working? At around 25 seconds I see a DataStores error.

The error is only happening with math.huge, if you try to save for exemple 9M and rejoin it will not be saved.

It makes sense. You can’t save an infinite amount of numbers in a data store. Data store has a limit.

If Roblox were to fix “inf” then they would have to not take infinite bytes to save I guess.

Inf doesnt normally happen unless you play forever so you good. Gameplay is normal

1 Like