Datastores aren't working

Hello! So I was making a game with a friend and then this happened

Idk how it happened but are data wasn’t saving.

Heres the stats script

local dataStores = game:GetService("DataStoreService"):GetDataStore("TixDataStore")
local defaultTix = 0
local playersLeft = 0

game.Players.PlayerAdded:Connect(function(player)
	
	playersLeft = playersLeft + 1
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local Tix = Instance.new("IntValue")
	Tix.Name = "Tix"
	Tix.Value = 0
	Tix.Parent = leaderstats
	
	local Wins = Instance.new("IntValue")
	Wins.Name = "Wins"
	Wins.Value = 0
	Wins.Parent = leaderstats
	
	player.CharacterAdded:Connect(function(character)
		
		character.Humanoid.Died:Connect(function()
			-- Whenever sombody dies, this event will run
			if character:FindFirstChild("GameTag") then
				character.GameTag:Destroy()
			end
			
			player:LoadCharacter()
		end)
		
	end)
	
	-- Data Stores
	
	local player_data
	
	pcall(function()
		player_data = dataStores:GetAsync(player.UserId.."-Tix") -- 000000-Tix
		
		player_data = dataStores:GetAsync(player.UserId.."-Wins") -- 000000-Wins
	end)
	
	if player_data ~= nil then
		-- Player has ssaved data, load it in
		Tix.Value = player_data
	else
		-- New Player
		Tix.Value = defaultTix
	end
	
end)

local bindableEvent = Instance.new("BindableEvent")

game.Players.PlayerRemoving:Connect(function(player)
	
	pcall(function()
		dataStores:SetAsync(player.UserId.."-Tix",player.leaderstats.Tix.Value)
		dataStores:SetAsync(player.UserId.."-Wins",player.leaderstats.Wins.Value)
		print("Players Data Has Succsessfully Saved!")
		playersLeft = playersLeft - 1
		bindableEvent:Fire()
	end)
	
end)

game:BindToClose(function()
	-- This will be triggered upon shutdown
	while playersLeft > 0 do
		bindableEvent.Event:Wait()
	end
end)

Everything is working. You have used up the maximum amount of DataStore requests and sends.
Edit: It gets put in a queue.
Just wait.

1 Like

but when me and him rejoined the game for some reason, are data was corrupted and then he had 3 tix and 0 wins and I had 2 tix when before we had like 50 and 25

I recommend learning how to use tables. And Creating a data table for those values because if you continue with your current method you won’t be able to store other data if you wish to.

Example

local player_data = {Tix = Tix.Value,Wins = Wins.Value}

This will allow you to keep the amount of request you use to a very low minimum if you decided to create one huge data-table instead of a bunch of datastores for one person.

1 Like

Just wait. Like I literally just said.

it never worked :expressionless:


If using the example I provided when retrieving the data it would be a table with two values Tix & Wins

if player_data ~= nil then
		-- Player has ssaved data, load it in
		Tix.Value = player_data.Tix
		Wins.Value = player_data.Wins

	else
		-- New Player
		Tix.Value = defaultTix
	end