Can you active math.random in a function

Hi, I wanted to ask if you can activate math.random in a func even if its outside of a script, It might be hard to explain but this is what I am asking about

local random = math.random(1, 5)
local part = script.Parent

part.touched:connect(function()
random = math.random(1,5)
end)

you can use empty variables.

local random
local part = script.Parent

part.touched:connect(function()
random = math.random(1,5)
end)
1 Like

You can’t have anything outside of scripts, lol

do you want the function to be activated outside of the script or change a value outside of the script?

i donot think i understood this well but yes you can use math.random in a function

local function random(m, n)
	return math.random(m, n) -- math.random in a function 
end

for i=1,10 do
	print(random(1,5)) -- will print different number each time
end

however, this is a bit worse for perforance