Require() freezing & time out, is it roblox or is it me?

I dont even know whats happening, apparently Roblox reports that at line 1545 of a serverside script:

local ArmorData = require(ServerStorage.Modules.Armour)

is causing script timeout. It froze for several seconds weirdly.
Heres the Armour module, as you mightve read there is no explicit while loops, recursions, severe yielding,…

local ArmorData = {}
print("Hey1")

ArmorData.SlotInfo = {
	Helmet = { Coverage = 0.20 },
	Chestplate = { Coverage = 0.45 },
	Leggings = { Coverage = 0.30 },
}

ArmorData.Stats = {
	["Iron"] = {
		Sharp = 0.66666666666666666666666666666666666666666,
		Blunt = 0.5,
		Blast = 0.55555555555555555555555555555555555555555,
		Bleed = 0.83333333333333333333333333333333333333,
		Burning = 0.90909090909090909090909090909090909090909,
		Freezing = 0.90909090909090909090909090909090909090909,
		Natural = 0.90909090909090909090909090909090909090909,
		Aerial = 0.8,
	},

	["Titanium"] = {
		Sharp = 0.4,
		Blunt = 0.333333333333333333333333333333333333333333,
		Blast = 0.4,
		Bleed = 0.4,
		Burning = 0.5,
		Freezing = 0.5,
		Toxic = 0.66666666666666666666666666666666666666666,
		Holy = 0.6666666666666666666666666666666666666666666,
		Tainted = 0.83333333333333333333333333333333333333,

		Natural = 0.66666666666666666666666666666666666666666,
		Water = 0.83333333333333333333333333333333333333,
		Aerial = 0.5,
	},
	
	["Mithril"] = {
		Sharp = 0.3333333333333333333333333333333333333333333,
		Blunt = 0.4,
		Blast = 0.625,

		Bleed = 0.25,
		Burning = 0.83333333333333333333333333333333333333333,
		Freezing = 0.33333333333333333333333333333333333333333,
		Toxic = 0.5,
		Holy = 0.8,
		Tainted = 0.76923076923076923076923076923076923076923,

		Natural = 0.66666666666666666666666666666666666666666,
		Magic = 0.952380952380952380952380952380952380952380,
		Water = 0.83333333333333333333333333333333333333,
		Aerial = 0.5,
	},
	
	["Obsidian"] = {
		Sharp = 0.25,
		Blunt = 0.8333333333333333333333333333333333333333333,
		Blast = 1.05,
		Bleed = 0.3333333333333333333333333333333333333333,
		Burning = 0.33333333333333333333333333333333333333333,
		Freezing = 0.8333333333333333333333333333333333333333,
		Toxic = 0.4,
		Holy = 0.8,
		Tainted = 0.714285714285714285714285714285714285714285,
		Natural = 0.5,
		Magic = 0.952380952380952380952380952380952380952380,
		Water = 0.76923076923076923076923076923076923076923,
		Aerial = 0.9090909090909090909090909090909090909090909,
		Shocking = 0.666666666666666666666666666666666666666,
	},
	
	
	
	
	
	
	
	
	
	---- BOSS STATS ----
	
	["BlackLotus"] = {
		Sharp = 1.5,
		Blunt = 0.6666666666666666666666666666666666666666666,
		Bleed = 1.6,
		Burning = 2.5,
		Freezing = 2,
		Toxic = 0,
		Holy = 1,
		Tainted = 0.4,
		Natural = 0.5,
		Magic = 0.952380952380952380952380952380952380952380,
		Water = 0.1,
		Aerial = 1,
		Shocking = 1,
		Soul = 0.5,
		Blast = 2
	},
	
	["Ignis"] = {
		
	}
}

ArmorData.Durability = {
	-- TIER 1
	Iron = {
		Leggings = 900,
		Chestplate = 1250,
		Helmet = 600,
	},

	-- TIER 2
	Obsidian = {
		Leggings = 1100,
		Chestplate = 1800,
		Helmet = 800,
	},
	
	Titanium = {
		Leggings = 1400,
		Chestplate = 2000,
		Helmet = 1000,
	},
	Mithril = {
		Leggings = 1300,
		Chestplate = 1900,
		Helmet = 950,
	},

	-- TIER 3 ALT
	Rotten = {
		Leggings = 1200,
		Chestplate = 1750,
		Helmet = 850,
	},
	Pandemite = {
		Leggings = 1800,
		Chestplate = 2600,
		Helmet = 1400,
	},
	Fire_Spirit = {
		Leggings = 1700,
		Chestplate = 2450,
		Helmet = 1300,
	},
	Water_Spirit = {
		Leggings = 1600,
		Chestplate = 2300,
		Helmet = 1250,
	},
	Wind_Spirit = {
		Leggings = 1150,
		Chestplate = 1600,
		Helmet = 800,
	},

	-- TIER 3
	Holy = {
		Leggings = 2500,
		Chestplate = 3500,
		Helmet = 2000,
	},
	Glacier = {
		Leggings = 2650,
		Chestplate = 3700,
		Helmet = 2100,
	},
	Molten = {
		Leggings = 2600,
		Chestplate = 3650,
		Helmet = 2050,
	},

	-- TIER 4 ALT
	Seraphic = {
		Leggings = 3200,
		Chestplate = 4600,
		Helmet = 2800,
	},
	Permafrost = {
		Leggings = 3400,
		Chestplate = 4850,
		Helmet = 2950,
	},
	Molten_Spirit = {
		Leggings = 3350,
		Chestplate = 4800,
		Helmet = 2900,
	},

	-- TIER 4
	Prismatic = {
		Leggings = 5000,
		Chestplate = 7000,
		Helmet = 4000,
	},
}

ArmorData.TypeColors = {
	-- Physical & Basic Types
	Sharp = Color3.fromRGB(192, 192, 192),
	Blunt = Color3.fromRGB(118, 63, 24),
	Bleed = Color3.fromRGB(216, 21, 21),
	Bleeding = Color3.fromRGB(173, 7, 7),       -- Status effect
	Blast = Color3.fromRGB(255, 150, 97),

	-- Elemental Types
	Burning = Color3.fromRGB(255, 98, 20),
	Freezing = Color3.fromRGB(175, 247, 255),
	Shocking = Color3.fromRGB(255, 242, 67),
	Water = Color3.fromRGB(65, 141, 255),
	Aerial = Color3.fromRGB(255, 255, 255),
	Radioactive = Color3.fromRGB(46, 232, 46),

	-- Esoteric & Magical Types
	Holy = Color3.fromRGB(255, 255, 165),
	Tainted = Color3.fromRGB(25, 16, 43),
	Toxic = Color3.fromRGB(104, 86, 195),
	Poison = Color3.fromRGB(104, 86, 195),      -- Status effect
	Natural = Color3.fromRGB(69, 202, 62),
	Magic = Color3.fromRGB(241, 138, 255),
	Soul = Color3.fromRGB(95, 131, 147),
	
	Byrrus = Color3.fromRGB(255, 26, 26),
	Luteus = Color3.fromRGB(255, 132, 25),
	Flavus = Color3.fromRGB(255, 232, 60),
	Viridis = Color3.fromRGB(36, 220, 26),
	Caerulus = Color3.fromRGB(53, 235, 235),
	Caesitas = Color3.fromRGB(39, 32, 235),
	Hyacinthinus = Color3.fromRGB(150, 21, 255),

	-- Miscellaneous (joke) Types
	Heal = Color3.fromRGB(70, 255, 138),
	God = Color3.fromRGB(255, 255, 255),


}

ArmorData.Weight = {
	Mithril = 1,
	Titanium = 0.9,
	Pandemite = 0.8,
	Iron = 0.85,
	Holy = 0.75,
	Obsidian = 0.7,
	Glacier = 0.7,
	Molten = 0.7,
	Prismatic = 0.625,
	
	BlackLotus = 0
}

function ArmorData.GetMultiplier(pieceName, damageType)
	if ArmorData.Stats[pieceName] and ArmorData.Stats[pieceName][damageType] then
		return ArmorData.Stats[pieceName][damageType]
	end
	return 1.0
end

function ArmorData.GetKB(pieceName)
	if ArmorData.Weight[pieceName] then
		return ArmorData.Weight[pieceName]
	end
	return 1.0
end

function ArmorData.CalculateDamageMultiplier(wornArmor: {[string]: string}, damageTypes: string | {string})
	
	local T = (typeof(damageTypes) == "string") and {damageTypes:split(",")} or damageTypes
	local N_types = #T
	if N_types == 0 then return 1 end

	local DamageAcc = table.create(N_types, 0)
	local TotalCoverage_Worn = 0

	for slot, pieceName in pairs(wornArmor) do
		local slotInfo = ArmorData.SlotInfo[slot]
		if slotInfo then
			local coverage = slotInfo.Coverage
			TotalCoverage_Worn += coverage

			for i = 1, N_types do
				DamageAcc[i] += coverage * ArmorData.GetMultiplier(pieceName, T[i])
			end
		end
	end

	local Coverage_Uncovered = 1.0 - math.clamp(TotalCoverage_Worn, 0.0, 1.0)

	local totalEffectiveMultiplier = 0
	for i = 1, N_types do
		totalEffectiveMultiplier += (DamageAcc[i] + Coverage_Uncovered)
	end

	return totalEffectiveMultiplier / N_types
end
print("Hey2")

return ArmorData

So… whats even causing this???

Heres the output when i run the game, ignore the table printed and the “This plugin …” bug at the end:

image

what is in gamehandler near line 1545

thats probably causing the issue

nope, no while loops recursion or long for loops either. Ive also tested sketchy looking while loops and went through all 14 while loops present in the script but every one of them worked fine and/or already have task.wait in it

did you tried to add at start line of script ?

or just create seperate modulescripts: one with table and one with functions

Without even taking a look at your code, you’ve created an infinite loop in your logic, or the workload is legit, but just more than is possible to process before the timeout kicks in.

Willing to bet on the former.

Unrelated to your question, but what are these numbers?

Why are you storing repeating decimals like this? There’s no need for so much precision.

Moreover, I don’t see the value in this over using a fraction (which will be constant folded and is negligible regardless).

1 Like

I think the fault is just that your 1.5k+ line GameHandler is taking too long to execute, and the require is just the straw that breaks the camel’s back.

nope, I have already checked the 14 while loops in the gamehandler script and none of them run infinitely. Even if so, the script would’ve reported at the specific while loop line.

yeaaa so its kind of a bad habit of perfection, I dont trust roblox’s precision either since I’ve seen those little floating point errors which really itches my perfectionism. By the way, I’ve added some code to the gamehandler script and now it shifted to line 1308, and it also happens to be on a require() section. Perhaps it really is because of the sheer size of the script, I should split it into several parts then

At this point, implement some breakpoints in your loops and manually step through them in order to better-gauge where it’s hanging.

Gotta dive deeper into the problem rather than throw your hands up in the air.

1 Like

Those floating point precision errors are still there regardless of how precisely you type it. You can run this right now to see they’re equivalent, print(string.format("\n%.32f\n%.32f", 1/3, 0.333333333333333333333333333333333333333333)).

oh. Well that helps in future fractional constants, thanks for making me realize this