Only One IntValue Showing on Leaderboard?

So, I’m writing a data saving leaderstats/leaderboard with multiple “IntValue”, but it only shows one.

local dataStoreService = game:GetService("DataStoreService")

function plrAdded(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local kills = Instance.new("IntValue")
	kills.Name = "Kills"
	kills.Parent = leaderstats
	kills.Value = dataStoreService:GetDataStore("Kills"):GetAsync(player.UserId) or 0

	local deaths = Instance.new("IntValue")
	deaths.Name = "Deaths"
	deaths.Parent = leaderstats
	deaths.Value = dataStoreService:GetDataStore("Deaths"):GetAsync(player.UserId) or 0
end
function plrRemoving(player)
	local datasave = dataStoreService:GetDataStore("Key0")
	local leaderstats = player:FindFirstChild("leaderstats")
	local deaths = leaderstats:FindFirstChild("Deaths")
	local kills = leaderstats:FindFirstChild("Kills")

	datasave:SetAsync("Deaths"..player.UserId, deaths.Value)
	datasave:SetAsync("Kills"..player.UserId, kills.Value)
end

players.PlayerAdded:Connect(plrAdded)
players.PlayerRemoving:Connect(plrRemoving)

DataSave

local dataStoreservice = game:GetService("DataStoreService")
local leaderstatsData = dataStoreservice:GetDataStore("leaderstats")

game.Players.PlayerAdded:Connect(function(player)

	local playerData = leaderstatsData:GetAsync(player.UserId)
	if not playerData then
		playerData = {
			Kills = 0
		}
		leaderstatsData:SetAsync(player.UserId, playerData)
	end

	player.leaderstats.Kills.Value = playerData
end)

game.Players.PlayerAdded:Connect(function(player)
	local playerData = leaderstatsData:GetAsync(player.UserId)
	if not playerData then
		playerData = {
			Deaths = 0
		}
		leaderstatsData:SetAsync(player.UserId, playerData)
	end

	player.leaderstats.Deaths.Value = playerData
end)

game.Players.PlayerRemoving:Connect(function(player)

	local playerData = {
		Kills = player.leaderstats.Kills.Value
	}
	leaderstatsData:SetAsync(player.UserId, playerData)
end)
game.Players.PlayerRemoving:Connect(function(player)

	local playerData = {
		Deaths = player.leaderstats.Deaths.Value
	}
	leaderstatsData:SetAsync(player.UserId, playerData)
end)

image

I’ve looked around the forums, but I couldn’t find the answer to my problem. Ask any questions you may need. Any help is appreciated, thank you!

1 Like

Your script worked for me, but I put it in my usual file I use to test things.

The only other change I made was removing the datastore request (changed to kills.Value = 0)




--==============
-- PLAYER ADDED
--==============

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)

	-- executes only when player joins
	
	print("adding leaderstats")
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local kills = Instance.new("IntValue")
	kills.Name = "Kills"
	kills.Parent = leaderstats
	kills.Value = 0
	--kills.Value = dataStoreService:GetDataStore("Kills"):GetAsync(player.UserId) or 0

	local deaths = Instance.new("IntValue")
	deaths.Name = "Deaths"
	deaths.Parent = leaderstats
	deaths.Value = 0
	--deaths.Value = dataStoreService:GetDataStore("Deaths"):GetAsync(player.UserId) or 0
	
	
	
	--=================
	-- CHARACTER ADDED
	--=================


	player.CharacterAdded:Connect(function(character)

		-- executes when player joins and each time player resets or dies



		--===============
		-- HUMANOID DIED
		--===============

		character.Humanoid.Died:Connect(function()

			-- executes only when a character resets or dies

		end)
	end)



	--============================
	-- CHARACTER APPEARANCE ADDED
	--============================

	player.CharacterAppearanceLoaded:Connect(function(character)

		-- will only run one time

	end)

end)



--=================
-- PLAYER REMOVING
--=================

Players.PlayerRemoving:Connect(function(player)

	-- executes only when player leaves games

end)
1 Like

Yeah, but i want it to save the player’s data

1 Like

Did it create both values when you just put 0 instead of trying to load the datastore?

Yes, but how do i get it to save in my datastore?

If only one of them works with checking the datastore then maybe something is wrong with the second request to the datastore.

I can’t seem to find the problem.

Dont do this.It will confuse and wont work and follow data saving youtube videos and see how they do it

and btw,save it in one data store.u are cretaing two of them.this results in only one varaible working