Generating random numbers in ModuleScript

hello

I have problem with ModuleScript and generated random numbers in ModuleScript
The value is constantly repeating

 local promena = {}

-- gain the last second of the current time time
local function ziskatPosledniSekunduAktualnihoCasu()
    -- Gaining the current time
    local currentTime = os.date("*t")
    -- Getting the last second
    local lastSecond = tonumber(string.sub(tostring(currentTime.sec), -1))
    return lastSecond
end

-- Function to generate random value based on current time
local function generovatNahodnouHodnotu()
    -- Getting the last second of the current time
    local lastSecond = ziskatPosledniSekunduAktualnihoCasu()
    -- Násobení poslední sekundy náhodným číslem v rozsahu od 1 do 500
    local seed = lastSecond * math.random(1, 500)
    -- Multiplication last second by random number in the range of 1 to 500
    math.randomseed(seed)
    -- Generating random value in the range of 1 to 500
    return math.random(1*lastSecond, 500*lastSecond)
end

promena.hodnota = generovatNahodnouHodnotu() -- Calling a function to generate random value

return promena

I have a question, When does Modulescipt be loaded ???

VideoExample:

thanks in advance

Cody

You have to call the function at runtime, it’s giving you the same value because your calling the function inside of the module script

1 Like

How can I call the function at runtime.
I’m more of a model and designer and from scripting I have a wind :upside_down_face:
Cody

Uh you basically have to call it in the script you wanna use the function at

1 Like

That’s what I was afraid of.
I don’t even give that at all :slight_smile:

It was enough to call from Modulescript from that I moved to Replicatedstorage

local promenaModule = require(game:GetService("ReplicatedStorage").Promena)
.......
.......
.......
local function updateRandomValue()
    promenaModule.hodnota = promenaModule.generovatNahodnouHodnotu()
end
.......
.......
.......
updateRandomValue()

Thanks --The Batman

VideoExapmple:

1 Like