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

Why is my math.random erroring?

Here is my math.random:

math.random(h-v, h+v)

Both are integers, and positive numbers. According to the wiki, this should work. Help please?

local Type=1
height=50
variation=10
speed=15
direction="z"


local Top=Workspace.TopLimit
local Bottom=Workspace.BottomLimit
---------- Function Setup -----------
function place(name)
	if script:FindFirstChild(name) then
		script:FindFirstChild(name).Parent=Game.ServerStorage
	end
end
function Cloud(s, h, v, d)
	local dir
	local c=Game.ServerStorage:FindFirstChild("Cloud"..Type)
	if d=="x" or d=="-x" then dir=c.XSpeed
		if d=="x"then
			dir.Value=s
		elseif dir.Value=="-x" then
			dir.Value=0-s
		end
	elseif d=="z" or d=="-z" then dir=c.ZSpeed
		if d=="z"then
			dir.Value=s
		elseif dir.Value=="-z" then
			dir.Value=0-s
	end end
	local high=math.random(h-v, h+v)
	if Top.Position.X>Bottom.Position.X then
	local ex=math.random(Top.Position.X, Bottom.Position.X)
	else
		local ex=math.random(Bottom.Position.X, Top.Position.X)
		end
	if Top.Position.Z>Bottom.Position.Z then
	local zee=math.random(Top.Position.Z, Bottom.Position.Z)
	else
		local zee=math.random(Bottom.Position.Z, Top.Position.Z)
		end
	c.Destroy.Disabled=false
	c.SpeedScript.Disabled=false
end
function Make()
	Cloud(speed, height, variation, direction)
end
----------- Move Assets ------------
local TestMode=false
if not TestMode then
for i=1, 5 do
place("Cloud"..i)
end
end

Workspace.MakeCloud.OnServerEvent:connect(Make)

----------- Main Script ------------
for i=1, frequency do
		Make()
end

6 comments

0

I can't think of how this would error without v being negative.

0

Error message, or is it always one?

0

Error message, the one about intervals, which means A is greater than B, which it's not

0

Just for the record, h=50 and v=10

1

Please post the entire script.

0

Please post the whole script or post the error message :)

1 answer

You never defined the variables correctly h = height v = variation s = speed

So, you were correct using math.random, just didn't use it the right way.

1 comment

0

function Make() 46 Cloud(speed, height, variation, direction) 47 end ---- So this didn't work?

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