Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

This math.random modulescript is giving me an error?

I am trying to use a module to calculate a random worth for a value, positive or negative, but it comes up with the error : 10:54:28.594 - Requested module experienced an error while loading. Please help?

Module script :

local microbloxGUI = game.Workspace.Part.SurfaceGui.Display1
local mbxChangeVal = microbloxGUI.mbxChange.change
local mbxWorthVal = microbloxGUI.mbxWorth.worth

local stockChange = {}

function stockChange.microblox()
	local change = math.random(1,2)
		if change == 1 then
			if microbloxGUI.mbxWorth.worth < 5 then
				microbloxGUI.mbxChange.change = math.random(0.1, 0.5)
					local endVal = mbxChangeVal.Value + mbxWorthVal.Value
					print("Microblox has gone up by" .. endVal .. " !")
			if microbloxGUI.mbxWorth.worth > 5 then
				microbloxGUI.mbxChange.change = math.random(0.35, 0.75)
					local endVal = mbxChangeVal.Value + mbxWorthVal.Value
					print("Microblox has gone down by" .. endVal .. " !")
				end
			end
		end
	end
end

return stockChange

Module action script

local stockChangeCalculator = require(game.Lighting.StockChangeMain)

stockChangeCalculator.microblox()

1 comment

1

There should be an accompanying error saying what the problem was when loading

1 answer

✓ Accepted answer

You are missing ends in places where there should be ends and have too many ends all at the same time.

Revised code

local microbloxGUI = game.Workspace.Part.SurfaceGui.Display1
local mbxChangeVal = microbloxGUI.mbxChange.change
local mbxWorthVal = microbloxGUI.mbxWorth.worth

local stockChange = {}

function stockChange.microblox()
    local change = math.random(1,2)
    if change == 1 then
        if microbloxGUI.mbxWorth.worth < 5 then
            microbloxGUI.mbxChange.change = math.random(0.1, 0.5)
            local endVal = mbxChangeVal.Value + mbxWorthVal.Value
            print("Microblox has gone up by" .. endVal .. " !")
        elseif microbloxGUI.mbxWorth.worth > 5 then
            microbloxGUI.mbxChange.change = math.random(0.35, 0.75)
            local endVal = mbxChangeVal.Value + mbxWorthVal.Value
            print("Microblox has gone down by" .. endVal .. " !")
        end
    end
end

return stockChange

This discussion is preserved as it was. New answers, comments, and votes are closed.