Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is my math.random erroring?

Asked by
trogyssy 221 Moderation Voter
10 years ago

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

0
I can't think of how this would error without `v` being negative. User#2 0 — 10y
0
Error message, or is it always one? FromLegoUniverse 264 — 10y
0
Error message, the one about intervals, which means A is greater than B, which it's not trogyssy 221 — 10y
0
Just for the record, h=50 and v=10 trogyssy 221 — 10y
View all comments (2 more)
1
Please post the entire script. Articulating 1335 — 10y
0
Please post the whole script or post the error message :) MunimR 125 — 10y

1 answer

Log in to vote
-1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago

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.

0
function Make() 46 Cloud(speed, height, variation, direction) 47 end ---- So this didn't work? trogyssy 221 — 10y
Ad

Answer this question