How do I "refresh" a random value?

context:

i found out that roblox has wind properties
decided to look up example code to create random wind cycles
roblox has basic code for this
i modify, make gusts completely random
want to do the same for base wind

local gustCycleDelay = 4
local gustCycleDuration = 3.5

local r_valx = math.random(1, 15)
local r_valy = math.random(2, 5)
local r_valz = math.random(1, 15)

local baseWind = Vector3.new(r_valx, 0, r_valz)
local gust = Vector3.new(r_valx, r_valy, r_valz)
local gustIntervals = 100
local dg = gustCycleDuration / gustIntervals
local dgf = dg / gustCycleDuration

workspace.GlobalWind = baseWind

task.wait(gustCycleDelay)

while true do
	for i = 1, gustIntervals do
		local f = math.sin(math.pi * dgf * i)
		workspace.GlobalWind = baseWind + f * gust
		task.wait(dg)
	end
	workspace.GlobalWind = baseWind
	task.wait(math.random() * gustCycleDelay)
end

code is above

i’m very new to boblox lua, and my goal with this script is to make it so wind is completely random, and ever changing, just like how a super windy & stormy area would be :blush:

1 Like

Make a function that returns random values :slight_smile:

It’ll return different values all the time since you’re calling the random math method

1 Like

will look into that, gonna figure out how functions work and hopefully make things super cool!!

1 Like

i can’t seem to figure it out, any idea how i could do it?

i seem to be getting different syntax errors depending on where i put the function, but they all turn out to be the same issue; expects one thing, gets something different.

not sure how to proceed :face_with_spiral_eyes:

1 Like

Sorry for long reply time but here

local functon GetRandomNumber(min: number, max: number) : number

return math.random(min, max) 
end


local RandomNumber = GetRandomNumber(0, 2) 
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.