DataStore issue

I want my Datastore to save my data and I get no errors in my script nor does it save my data. I’m confused about this and my friend and I are working to get this fixed but we still can’t find the problem with it. We’ve rewritten the script, read a lot of dev forum posts and we still haven’t found a solution.

 -------▂ ▄ ▅ ▆ ▇ █ SENTO DATASTORE █ ▇ ▆ ▅ ▄ ▂-------
local DataStore = game:GetService("DataStoreService")

--------------DATASTORES (STORAGE)--------------------
local sentodata = DataStore:GetDataStore("SentoDataStore")
---------------------DETECTOR---------------------------
game.Players.PlayerAdded:Connect(function(player)
	
	----------------DATA FOLDER-----------------
	local data = Instance.new("Folder", player)
	data.Name = "Data"
	local toSave
	--------------------------------------------

	-------------CREATE PHYSICAL VALUES-------------
	local clan = Instance.new("IntValue", data)
	local money = Instance.new("IntValue", data)
	local speed = Instance.new("IntValue", data)
	local strength = Instance.new("IntValue", data)
	local endurance = Instance.new("IntValue", data)
	local stamina = Instance.new("IntValue", data)
	local hunger = Instance.new("IntValue", data)
	local shakecam = Instance.new("BoolValue", data)
	local lastname = Instance.new("StringValue", data)
	local tier = Instance.new("StringValue", data)
	local rpname = Instance.new("StringValue", data)
	local combat = Instance.new("BoolValue", data)
	local style = Instance.new("IntValue", data)
	-------------------NAMING VALUES---------------------
	style.Name = "Style"
	clan.Name = "ClanName"
	money.Name = "Yen"	
	speed.Name = "Speed"
	strength.Name = "Strength"	
	endurance.Name = "Endurance"	
	stamina.Name = "Stamina"
	hunger.Name = "Hunger"
	shakecam.Name = "ShakeCam"
	lastname.Name = "LastName"
	tier.Name = "Tier"
	rpname.Name = "RPname"
	combat.Name = "Combat"
	------------------CHECKING DATA----------------------
	local success, err = pcall(function()
		toSave = sentodata:GetAsync(player.UserId)
	end)
	
	if success then
		if type(toSave) == "table" then
			--IF DATA DOES EXIST THEN
			clan.Value = toSave[1] or 1
			money.Value = toSave[2] or 0
			speed.Value = toSave[3]	or 20		--LOAD DATA
			strength.Value = toSave[4] or 0
			endurance.Value = toSave[5] or 0
			stamina.Value = toSave[6] or 10
			hunger.Value = toSave[7] or 1
			rpname.Value = toSave[8] or ""
			style.Value = toSave[9] or 1
		else
			--IF DATA DOES NOT EXIST THEN		
			clan.Value = 1	
			money.Value = 0
			speed.Value = 20			--DEFAULT VALUES.
			strength.Value = 0
			endurance.Value = 0
			stamina.Value = 10
			hunger.Value = 1
			rpname.Value = ""
			style.Value = 1
		end
	end
	
	------------------------SAVE DATA---------------------------
	--PUT ALL OF THE VARIABLES INTO A TABLE
	local toSaveData = {clan.Value, money.Value, speed.Value, strength.Value, endurance.Value, stamina.Value, hunger.Value, rpname.Value, style.Value}
	-------SAVE DATA ONE MORE TIME (WHEN THE PLAYER IS LEAVING THE GAME)-------
	clan.Changed:Connect(function()
		sentodata:SetAsync(player.UserId, toSaveData[1])
	end)
	
	money.Changed:Connect(function()
		sentodata:SetAsync(player.UserId, toSaveData[2])
	end)
	
	speed.Changed:Connect(function()
		sentodata:SetAsync(player.UserId, toSaveData[3])
	end)
	
	strength.Changed:Connect(function()
		sentodata:SetAsync(player.UserId, toSaveData[4])
	end)
	
	endurance.Changed:Connect(function()
		sentodata:SetAsync(player.UserId, toSaveData[5])
	end)
	
	stamina.Changed:Connect(function()
		sentodata:SetAsync(player.UserId, toSaveData[6])
	end)
	
	hunger.Changed:Connect(function()
		sentodata:SetAsync(player.UserId, toSaveData[7])
	end)
	
	rpname.Changed:Connect(function()
		sentodata:SetAsync(player.UserId, toSaveData[8])
	end)
	
	style.Changed:Connect(function()
		sentodata:SetAsync(player.UserId, toSaveData[9])
	end)
	
	game.Players.PlayerRemoving:Connect(function(player)
		sentodata:SetAsync(player.UserId, toSaveData)
	end)
	---------------------------------------------------------------------------
	
end)

There’s no need to save data whenever they’re changed. Just save them whenever a player leaves the game.

If I’m not mistaken, this is setting a players whole Datastore key to the value of toSaveData[1], this would completely erase any other values that were previously stored, or trying to store.

Secondly, you set a table with all of the values, but the values within this table will not update because you are not setting the table values upon the IntValue’s value changing. This would result in you storing the values that the player has joined with.

I would recommend you saving the players data upon PlayerRemoving. This would reduce the chance of getting throttled if an IntValue’s value were to change repeatedly. You should make the following edit:

local PlayerInfoTable = {}

game.Players.PlayerAdded:Connect(function(player)
	PlayerInfoTable[player.UserId] = {clan.Value, money.Value, speed.Value, strength.Value, endurance.Value, 		stamina.Value, hunger.Value, rpname.Value, style.Value}
		-------SAVE DATA ONE MORE TIME (WHEN THE PLAYER IS LEAVING THE GAME)-------
	clan.Changed:Connect(function(value)
		PlayerInfoTable[player.UserId][1] = value -- repeat changed event for the other IntValues
	end)
end)

game.Players.PlayerRemoving:Connect(function(player)
	local data = PlayerInfoTable[player.UserId]

	if data then
		sentodata:UpdateAsync(player.UserId, function(oldData)
			return data
		end)
	end
end)

++ you should read up on this post:
PSA: Don't use Instance.new() with parent argument