Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is my leaderboard only showing 1 category out of 2?

It only shows kills i need it to show exp to pls help.

local DS = game:GetService("DataStoreService")
local ExpStore = DS:GetOrderedDataStore("Exp")

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	
	local exp = Instance.new("IntValue", leaderstats)
	exp.Name = "Exp"
	
	pcall(function()
	local ExpVal = ExpStore:GetAsync(player.UserId)
	if ExpVal then
		exp.Value = ExpVal		
	end	
  end)

game.ServerStorage.GiveExp.Event:Connect(function(amount,plr)
	if player.Name == plr.Name then
		exp.Value = exp.Value + amount
	end
  end)
end)

game.Players.PlayerRemoving:Connect(function(player)
	pcall(function()
		if player:WaitForChild("leaderstats") and player.leaderstats:WaitForChild("Exp") and player.leaderstats.Exp.Value > 0 then
			ExpStore:SetAsync(player.UserId, player.leaderstats.Exp.Value)
			
		end
	end)
end)
---------------------------------------------------------------
local datastore = game:GetService("DataStoreService")
local KillsStore = datastore:GetOrderedDataStore("Kills")

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	
	local Kills = Instance.new("IntValue", leaderstats)
	Kills.Name = "Kills"
	
	pcall(function()
	local KillsVal = KillsStore:GetAsync(player.UserId)
	if KillsVal then
		Kills.Value = KillsVal		
	end	
  end)

game.ServerStorage.GiveKills.Event:Connect(function(amount,plr)
	if player.Name == plr.Name then
		Kills.Value = Kills.Value + amount
	end
  end)
end)

game.Players.PlayerRemoving:Connect(function(player)
	pcall(function()
		if player:WaitForChild("leaderstats") and player.leaderstats:WaitForChild("Kills") and player.leaderstats.Kills.Value > 0 then
			KillsStore:SetAsync(player.UserId, player.leaderstats.Kills.Value)
			
		end
	end)
end)

1 comment

0

first person to help get free sword on my game lol

1 answer

✓ Accepted answer

You have two contradicting leaderstat folders, the leaderboard isn’t sure which to read the data from, so I assume the first folder takes priority and is why the second is ignored. This is also a bad practice in general.

To solve your issue, just parent the Kills IntValue to the existing folder:


Note:

The parental argument of Instance.new() was deprecated, please always set the parent last after creating and effectively modifying the Object


local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
    local Leaderstats = Player:WaitForChild("leaderstats")
    local Kills = Instance.new("IntValue")
    Kills.Name = "Kills"
    Kills.Parent = Leaderstats
end)

2 comments

0

OMG THX FOR UR HELP i honestly would have never found that out myself ur the best :)

0

IT WORKED THANK U SO MUCH! ill make sure to shout u out in my game description ;)

This discussion is preserved as it was. New answers, comments, and votes are closed.