Need help on module script

i was doing a “Mod system” where i can do stuff, like upgrading stats or simply calculate what type of buff they receive, the problem is that once i try to print to see that it returns my values, i get this:

image

Which is supposed to be the print of this local script:

local mods = require(game.ReplicatedStorage.Modules.ModuleMods)

print(mods.RankCalculate(1, "Weapon Master", 1,"Both",1,1))

What can i do to fix this problem?

This is the module script:

local Mods = {
	
	["Busted Tank"] = {
		StatsChange = {Buff = {30, 0, 0}, Nerf = {20, 0}, TypeOfBuff = "MaxHP", TypeOfNerf = "Armor", BuffType = "Additive", NerfType = "Additive"},
		SpecialEffect = "None",
		Rarity = "Rare",
		MaxRank = 1,
		Capacity = {MinCapacity = 7, MaxCapacity = 7}
	},
	
	["Broken Armor"] = {
		StatsChange = {Buff = {50, 0, 0}, Nerf = {10, 0}, TypeOfBuff = "Armor", TypeOfNerf = "MaxHP", BuffType = "Additive", NerfType = "Additive"},
		SpecialEffect = "When at half HP, You lose the buff but you gain the same total of your depleted Max HP",
		Rarity = "Uncommon",
		MaxRank = 5,
		Capacity = {MinCapacity = 5, MaxCapacity = 10}
	},
	
	["Determination"] = {
		StatsChange = {Buff = {0, 0, 0}, Nerf = {0, 0}, TypeOfBuff = "None", TypeOfNerf = "None", BuffType = "None", NerfType = "None"},
		SpecialEffect = "Whoever has this mod can change it's effects at their pleasure, But watch out, Stronger the mod is, More capacity it will request",
		Rarity = "Legendary",
		MaxRank = 0,
		Capacity = {MinCapacity = 0, MaxCapacity = 30}
	},
	
	["Running Boots"] = {
		StatsChange = {Buff = {3, 0, 0}, Nerf = {3, 0}, TypeOfBuff = "RSspeed", TypeOfNerf = "WSspeed", BuffType = "Additive", NerfType = "Additive"},
		SpecialEffect = "None",
		Rarity = "Common",
		MaxRank = 3,
		Capacity = {MinCapacity = 4, MaxCapacity = 7}
	},
	
	["Weapon Master"] = {
		StatsChange = {Buff = {1.4, 0, 0}, Nerf = {0.6, 0}, TypeOfBuff = "WeaponDMG", TypeOfNerf = "NonWeaponDMG", BuffType = "Multiplicative", NerfType = "Multiplicative"},
		SpecialEffect = "None",
		Rarity = "Rare",
		MaxRank = 10,
		Capacity = {MinCapacity = 3, MaxCapacity = 13}
	}
}

function Mods.RankCalculate(plr, ModName, CurrentRank, BuffOrNerfOrBoth:string, BuffID, NerfID)
	local Mod = Mods[ModName]
	local finalValueBuff, finalValueNerf, newBuff, newNerf
	
	if not Mod then
		return nil, "Mod not found"
	end
	
	if BuffID ~= nil then
		finalValueBuff = Mod.StatsChange.Buff[BuffID]
	else
		finalValueBuff = {}
		for _, Buff in ipairs(Mod.StatsChange.Buff) do
			if Buff ~= 0 then
				table.insert(finalValueBuff or {}, Buff)
			end
		end
	end
	
	if NerfID ~= nil then
		finalValueNerf = Mod.StatsChange.Nerf[NerfID]
	else
		finalValueNerf = {}
		for _, Nerf in ipairs(Mod.StatsChange.Nerf) do
			if Nerf ~= 0 then
				table.insert(finalValueNerf or {}, Nerf)
			end
		end
	end
	
	local initialValueBuff = 1.05
	local initialValueNerf = 0.95
	local maxRank = Mod.MaxRank

	local function calculateBase(initialValue, finalValue, maxRank)
		return (finalValue / initialValue) ^ (1 / (maxRank - 1))
	end

	local function exponentialValue(initialValue, base, rank)
		return initialValue * (base ^ (rank - 1))
	end
	
	if type(finalValueBuff) == "table" then
		if Mod.BuffType == "Additive" then
			for i, value in ipairs(finalValueBuff) do
				newBuff[i] = math.round((value/((maxRank-CurrentRank) + 1))*100)/100
			end
		elseif Mod.BuffType == "Multiplicative" then
			for i, value in ipairs(finalValueBuff) do
				local baseBuff = calculateBase(initialValueBuff, value, maxRank)
				newBuff[i] = math.round(exponentialValue(initialValueBuff, baseBuff, CurrentRank)*100)/100
			end
		end
	else
		if Mod.BuffType == "Additive" then
			newBuff = math.round((finalValueBuff / ((maxRank-CurrentRank) + 1))*100)/100
		elseif Mod.BuffType == "Multiplicative" then
			local baseBuff = calculateBase(initialValueBuff, finalValueBuff, maxRank)

			local newBuff = math.round(exponentialValue(initialValueBuff, baseBuff, CurrentRank)*100)/100
		end
	end
	
	if type(finalValueNerf) == "table" then
		if Mod.NerfType == "Additive" then
			for i, value in ipairs(finalValueNerf) do
				newNerf[i] = math.round((value/((maxRank-CurrentRank) + 1))*100)/100
			end
		elseif Mod.NerfType == "Multiplicative" then
			for i, value in ipairs(finalValueNerf) do
				local baseNerf = calculateBase(initialValueNerf, value, maxRank)
				newNerf[i] = math.round(exponentialValue(initialValueBuff, baseNerf, CurrentRank)*100)/100
			end
		end
	else
		if Mod.NerfType == "Additive" then
			newNerf = math.round((finalValueNerf / ((maxRank-CurrentRank) +1))*100)/100
		elseif Mod.NerfType == "Multiplicative" then
			local baseNerf = calculateBase(initialValueNerf, finalValueNerf, maxRank)
			
			local newNerf = math.round(exponentialValue(initialValueNerf, baseNerf, CurrentRank)*100)/100
		end
	end
	
	if newBuff and not newNerf then
		return newBuff
	elseif newNerf and not newBuff then
		return newNerf
	elseif newBuff and newNerf then
		return newNerf, newBuff
	end
end

return Mods

i suspect about the return part, but i dont know how to make them return the exact values since they are more than 1 per variable since there are tables

BuffType is a key in Mod.StatsChange, not Mod

		if Mod.StatsChange.BuffType == "Additive" then
			newBuff = math.round((finalValueBuff / ((maxRank-CurrentRank) + 1))*100)/100
		elseif Mod.StatsChange.BuffType == "Multiplicative" then
			local baseBuff = calculateBase(initialValueBuff, finalValueBuff, maxRank)

			local newBuff = math.round(exponentialValue(initialValueBuff, baseBuff, CurrentRank)*100)/100
		end
1 Like

Oh… im actually stupid, thank you but after that change it doesn’t change the output

Still the empty output

remove the local keyword on this line

1 Like

Thank you, it was mostly a distracted error, i may need a break after that due to “Overworking” on the scripts, Basically by adjusting the Key and then adjusting the local made it work

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