Leaderboard get created 2 times for no reason

My game leaderstats created 2 times for no reason.

Image

image

Leaderstats Script
local groupid = 10830638

local DB = game:GetService("DataStoreService");
local MinDB = DB:GetDataStore("MinStats");

game.Players.PlayerAdded:connect(function(player)
	local leaderstats = Instance.new("Folder", player);
	leaderstats.Name = "leaderstats";

	local Minutes = Instance.new("IntValue", leaderstats);
	local Coins = Instance.new("IntValue", leaderstats);
	local Rebirth = Instance.new("IntValue", leaderstats)
	local Gems = Instance.new("IntValue", leaderstats)

	Minutes.Name = "Minutes"; 
	Coins.Name = "Coins";
	Rebirth.Name = "Rebirth";
	Gems.Name = "Gems";
	
	Minutes.Value = 0;
	pcall(function()
		Minutes.Value = MinDB:GetAsync(player.UserId) or 0;
	end)
	coroutine.wrap(function()
		while wait(60) do 
			Minutes.Value = Minutes.Value + 1;
		end
	end)()
end)

game.Players.PlayerRemoving:connect(function(player)
	pcall(function()
		if (player:FindFirstChild("leaderstats")) then
			MinDB:SetAsync(player.UserId, player.leaderstats.Minutes.Value);
		end
	end)
end)

I even try with “Find All/Replace All” to find leaderstats, rebirths and more keywords which you need when create a new leaderstats. But no clue…

1 Like

it could be you have another script that also creates leaderstats ,check all your scripts

Its another script’s actions, use “Find All/Replace All” with a bit more keywords this time

Just realised, you need to use the search “Instance.new(“Folder”)” and it will narrow it down
Searching is the most common answer here

Could it be bugs? Because I search almost 1 hours

It could be by using :connect() instead of :Connect()
The lower case function is deprecated, which may be causing it to fire two times.

It result that it was Studio bugs, I tested it in game instead of studio and it work smoothly.

are you sure that you dont have any suspicious scripts from free models?

Nope. It work well till I script something which related with leaderboard. xD

did u get any free model? if have u can check the free model script

Nevermind, the folders are different. Make sure you have no free models that create “leaderstats”

In the script look for a folder called “leaderstats”. If it already exists, then don’t create one, else just create a new one with values.