Leaderstats not working correctly

So I have a leaderstat and someone in my game did something that should make it go up by 1, but randomly it went up by 100k. Its working perfectly other than that one time. However, now he is no1 on the leaderboard and when i tried to reset the stats, it did nothing. I’ve tried resetting it multiple ways such as admin commands, and using the command bar in studio but nothing seems to be working, I can reset everyone elses stats perfectly fine. Any idea why this is?

It could be a visual glitch or they could be hacking you might want to investigate further and maybe ban the person or just exclude them from your leader board system.

1 Like

They werent hacking or anything, it was my friend, thats what makes it weirder.

Does your friend have access toy your data stores? If so they may be edited something that caused this to happen.

1 Like

Nope, basically what happened is theres a donation feature and they donated 20 to me, but it just said they donated 100k. I tested it again and it was perfectly fine

Ah have you tried setting there data equal to nil?

1 Like

It’s most likely an obscure code issue. Can you send the code?

1 Like

Yep I did the

local userKey = "1169791352";
local dss = game:GetService("DataStoreService");
local userData = dss:GetDataStore("DataStoreName");

userData:RemoveAsync(userKey);

in the command bar

This is the leaderboard code

-- [ SETTINGS ] --

local statsName = "Donated" -- Your stats name
local maxItems = 100 -- Max number of items to be displayed on the leaderboard
local minValueDisplay = 0 -- Any numbers lower than this will be excluded
local maxValueDisplay = 10e15 -- (10 ^ 15) Any numbers higher than this will be excluded
local abbreviateValue = true -- The displayed number gets abbreviated to make it "human readable"
local updateEvery = 90 -- (in seconds) How often the leaderboard has to update
local dummy = game.Workspace:WaitForChild("TopDonatedStatue")

-- [ END SETTINGS ] --




-- Don't edit if you don't know what you're doing --

local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local DataStore = DataStoreService:GetOrderedDataStore("GlobalLeaderboard_" .. statsName)
local Frame = script.Parent.Frame
local Contents = Frame.Contents
local Template = script.objTemplate

local COLORS = {
	Default = Color3.fromRGB(255, 255, 255),
	Gold = Color3.fromRGB(255, 215, 0),
	Silver = Color3.fromRGB(192, 192, 192),
	Bronze = Color3.fromRGB(205, 127, 50)
}
local ABBREVIATIONS = { "K", "M", "B", "T" }


local function toHumanReadableNumber(num)
	if num < 1000 then
		return tostring(num)
	end
	
	local digits = math.floor(math.log10(num)) + 1
	local index = math.min(#ABBREVIATIONS, math.floor((digits - 1) / 3))
	local front = num / math.pow(10, index * 3)
	
	return string.format("%i%s+", front, ABBREVIATIONS[index])
end

local function getItems()
	local data = DataStore:GetSortedAsync(false, maxItems, minValueDisplay, maxValueDisplay)
	local topPage = data:GetCurrentPage()

	Contents.Items.Nothing.Visible = #topPage == 0 and true or false

	for position, v in ipairs(topPage) do
		local userId = v.key
		local value = v.value
		local username = "[Not Available]"
		local color = COLORS.Default

		local success, err = pcall(function()
			username = Players:GetNameFromUserIdAsync(userId)
		end)

		if position == 1 then
			color = COLORS.Gold
			dummy.Humanoid:ApplyDescription(game.Players:GetHumanoidDescriptionFromUserId(userId))
			
		elseif position == 2 then
			color = COLORS.Silver
		elseif position == 3 then
			color = COLORS.Bronze
		end

		local item = Template:Clone()
		item.Name = username
		item.LayoutOrder = position
		item.Values.Number.TextColor3 = color
		item.Values.Number.Text = position
		item.Values.Username.Text = username
		item.Values.Value.Text = abbreviateValue and toHumanReadableNumber(value) or value
		item.Parent = Contents.Items
	end
end

while true do
	for _, player in pairs(Players:GetPlayers()) do
		local leaderstats = player:FindFirstChild("leaderstats")

		if not leaderstats then
			warn("Couldn't find leaderstats!")
			break
		end

		local statsValue = leaderstats:FindFirstChild(statsName)

		if not statsValue then
			warn("Couldn't find " .. statsName .. " in leaderstats!")
			break
		end

		pcall(function()
			DataStore:UpdateAsync(player.UserId, function()
				return tonumber(statsValue.Value)
			end)
		end)
	end

	for _, item in pairs(Contents.Items:GetChildren()) do
		if item:IsA("Frame") then
			item:Destroy()
		end
	end

	getItems()

	wait()
	Contents.GuideTopBar.Value.Text = statsName
	wait(updateEvery)
end

This is where i create the leaderstat

local players = game:GetService("Players")
local dataStoreService = game:GetService("DataStoreService")
local playerSaves = dataStoreService:GetDataStore("PlayerSaves")


players.PlayerAdded:Connect(function(player)
	
	local stats = Instance.new("Folder")
	stats.Name = "leaderstats"
	stats.Parent = player
	local kills = Instance.new("NumberValue")
	kills.Name = "Kills"
	kills.Parent = stats
	local donated = Instance.new("NumberValue")
	donated.Name = "Donated"
	donated.Parent = stats
	local wins = Instance.new("NumberValue")
	wins.Name = "Wins"
	wins.Parent = stats
	local winstreak = Instance.new("NumberValue")
	winstreak.Name = "Winstreak"
	winstreak.Parent = stats
	local deaths = Instance.new("NumberValue")
	deaths.Name = "Deaths"
	deaths.Parent = stats

Ok, so its all fixed now, for whatever reason when he was in the game with me it let me reset them, still weird how i could reset everyone elses when they werent in the game but with his he had to be in the game. Thanks for your help

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.