[UNSOLVED] Infinite yield possible on Leaderstats:WaitForChild

whichever script you want me to fix errors for. Idk which one you’re focusing on for this post

I have a few which one of works, and this is one of them which dont work, even if I take the working script and put it in unedited it doesnt work anymore, maybe because its a duplicate then but when I configure the working one to work with the correct stats it still doesnt work, this is the not working which should work:

local TextLabel = script.Parent
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Module = require(game.StarterGui.Module:WaitForChild("UnLockedModule"))

local Abbrevations_ = { "K", "M", "B", "T", "AA", "AB", "AC", "AD", "AE", "AF", "AG", "AH", "AI", "AJ", "AK", "AL", "AM", "AN", "AO", "AP", "AQ", "AR", "AS", "AT", "AU", "AV", "AW", "AX", "AY", "AZ" }

local function toHumanReadableNumber(num)
	if Module.Data.Abbrevations == 0 then
		if num < 1000 then
			return tostring(num)
		end

		local digits = math.floor(math.log10(num)) + 1
		local index = math.min(#Abbrevations_, math.floor((digits - 1) / 3))
		local front = num / 10^(index * 3)

		return string.format("%.1f%s+", front, Abbrevations_[index])
	elseif Module.Data.Abbrevations == 1 then
		local formattedNumber = tostring(num)
		local parts = {}
		local length = #formattedNumber
		local remainder = length % 3
		if remainder ~= 0 then
			parts[#parts + 1] = formattedNumber:sub(1, remainder)
		end
		for i = remainder + 1, length, 3 do
			parts[#parts + 1] = formattedNumber:sub(i, i + 2)
		end
		return table.concat(parts, ".")
	else
		local formattedNumber = tostring(num)
		local parts = {}
		local length = #formattedNumber
		local remainder = length % 3
		if remainder ~= 0 then
			parts[#parts + 1] = formattedNumber:sub(1, remainder)
		end
		for i = remainder + 1, length, 3 do
			parts[#parts + 1] = formattedNumber:sub(i, i + 2)
		end
		return table.concat(parts, ".")
	end
end

function updateTextLabel(value)
	TextLabel.Text = toHumanReadableNumber(value)
end

local towerTokensValue = Player:WaitForChild("leaderstats"):WaitForChild("Wins",30).Value
updateTextLabel(towerTokensValue)

if game.ReplicatedStorage:WaitForChild("DataStoreLoadedV").Value == 0 then
	game.ReplicatedStorage:WaitForChild("DataStoreLoadedV"):GetPropertyChangedSignal("Value")
	wait(5)
else
	wait(5)
end

local function refresh()
	local towerTokensValue = Player:WaitForChild("leaderstats"):WaitForChild("Wins",30).Value
	updateTextLabel(towerTokensValue)
end

local function checkForAbbrevationsChange()
	local currentValue = Module.Data.Abbrevations
	while true do
		wait(1)
		if Module.Data.Abbrevations ~= currentValue then
			refresh()
			currentValue = Module.Data.Abbrevations
		end
	end
end

Player:WaitForChild("leaderstats"):WaitForChild("Wins",30).Changed:Connect(refresh)
spawn(checkForAbbrevationsChange)

refresh()

this is the working script that doesnt work if duplicated or configured for a new value:

local TextLabel = script.Parent
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Module = require(game.StarterGui.Module:WaitForChild("UnLockedModule"))

local Abbrevations_ = { "K", "M", "B", "T", "AA", "AB", "AC", "AD", "AE", "AF", "AG", "AH", "AI", "AJ", "AK", "AL", "AM", "AN", "AO", "AP", "AQ", "AR", "AS", "AT", "AU", "AV", "AW", "AX", "AY", "AZ" }

local function toHumanReadableNumber(num)
	if Module.Data.Abbrevations == 1 then
		if num < 1000 then
			return tostring(num)
		end
		local digits = math.floor(math.log10(num)) + 1
		local index = math.min(#Abbrevations_, math.floor((digits - 1) / 3))
		local front = num / 10^(index * 3)
		return string.format("%.1f%s+", front, Abbrevations_[index])
	elseif Module.Data.Abbrevations == 0 then
		local formattedNumber = tostring(num)
		local parts = {}
		local length = #formattedNumber
		local remainder = length % 3
		if remainder ~= 0 then
			parts[#parts + 1] = formattedNumber:sub(1, remainder)
		end
		for i = remainder + 1, length, 3 do
			parts[#parts + 1] = formattedNumber:sub(i, i + 2)
		end
		return table.concat(parts, ".")
	else
		return tostring(num)
	end
end

function updateTextLabel(value)
	TextLabel.Text = toHumanReadableNumber(value)
end

local function refresh()
	local towerTokensValue = Player:WaitForChild("leaderstats"):WaitForChild("TowerTokens").Value
	updateTextLabel(towerTokensValue)
end

local function checkForAbbrevationsChange()
	local currentValue = Module.Data.Abbrevations
	while true do
		wait(1)
		if Module.Data.Abbrevations ~= currentValue then
			refresh()
			currentValue = Module.Data.Abbrevations
		end
	end
end

Player:WaitForChild("leaderstats"):WaitForChild("TowerTokens").Changed:Connect(refresh)
spawn(checkForAbbrevationsChange)

refresh()

Well in the refresh function you use waitforchild() but considering it only triggers when the value is indeed loaded in their is no need to use waitForChild().

So far thats all I’ve spotted

Yeah its pretty weird, I also have it with player collision disablers, running scripts exc, all work everywhere, efficient but my lobby, nothing interfering or anything, its also with this, it works but only for 1 of all 5 and for the first player all 5 work so its not like I made a spelling mistake because then it would work for nobody.

Sounds like its a problem to do with scripts interacting with each other and just a whole lot of bugs.

The only real way to fix this is is loads of trial and error or just restarting the code from the begging and probably making all leaderstats scripts just be one, cause less is more ig.

anyhow good luck

There is nothing interfering with eachother, ive check multiple times with the find all function to search for interfering code but found nothing all times. Thanks a lot though for your time.

1 Like