How do I get a variable from a function?

Say I have a module script with this function inside of it:

local function BuyRune(Player, Rune, RuneInfo)
	local luckequation = Player.Data.PlayerData.Luck.Value + Player.Data.Upgrades.Luck.Value
	local bulkequation = Player.Data.PlayerData.Bulk.Value 
	local cloneequation = Player.Data.PlayerData.RClone.Value

	local RuneLuck, chosenRunes = luckequation, {}

	for i = 1, bulkequation do
		local ChosenRune = ChooseRandomRune(Player, RuneInfo, RuneLuck)
		chosenRunes[ChosenRune] = (chosenRunes[ChosenRune] or 0) + cloneequation + 1
		Player.Data.PlayerData["Runes Opened"].Value += 1
		if i % 100000 == 0 then task.wait() end

	for chosenRuneName, chosenAmount in pairs(chosenRunes) do
		Player.Data.Runes[chosenRuneName].Value += chosenAmount

I would like to access the “luckequation” variable from a different script

How would I do that?

You can make it into a NumberValue and export it as a field on the table, that way you will be able it to pull it off I believe.

You’re using a module, but isn’t a purpose a bit defeated if you don’t use OOP? Why not create a separate variable outside of that scope, and access it from anywhere else in the module, if you need an even higher scope, you can use a NumberValue to access it from anywhere outside of that module.

I use modules myself to clean up scripts of clutter and calculations. I’ve been trying to use OOP myself but it’s concepts might seem simple to younger people, for me it’s hard. I can understand constructors, inheritance etc. and follow along as the instructor teaching but at no point can I put that knowledge into practice. It’s like ok lets make a shooting game, I’ll need a gun class (makes gun class), now what??? That’s as far as I ever get.

Use attributes and set the value to a shared object like the player.

Player:SetAttribute("LuckEquation", luckequation) -- call this every time luckequation updates

From another script:

local luckequation = Player:GetAttribute("LuckEquation") -- call this if you think the value has changed since you last checked