newstring = string.gsub(oldstring, "hello", number())
number() is a function that returns a random number I'm trying to make it so i replace all matches of "hello" to a random number, however whenever I use the script above it just turns every "hello" into one randomly generated number.
e.g Current string:
"hello hi hello hi hello hi"
what I'm trying to get:
"4 hi 7 hi 2 hi"
what happens:
"3 hi 3 hi 3 hi"
Rather than using number()
which evaluates to a random number, use number
which is a function that evaluates to a random number when called. Functions are first-class types in Lua, and can be passed about just like any other variable.