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

math.random() always picking the number 1?

Asked by 7 years ago
Edited 7 years ago

Also, math.Random(0,4) WONT WORK

So, i am making something so this briefcase will teleport to 1 of 4 positions. The script works fine, but its always picking position one. Can someone help me?

local map = "hub"
local pick = 0
local CSPAWN = 0


pick = math.random(1)

if pick == 1 then
    map = "concept"
    print(map)
end





if map == "concept" then
    CSPAWN = math.random(4)
    if CSPAWN == 1 then
    game.Workspace.Maps.Concept["The concept suitcase!"].Handle.Position = Vector3.new(-422.5, 1.5, -98.7)
    end
    if CSPAWN == 2 then
    game.Workspace.Maps.Concept["The concept suitcase!"].Handle.Position = Vector3.new(-355.5, 1.5, -184.55)
    end
    if CSPAWN == 3 then
    game.Workspace.Maps.Concept["The concept suitcase!"].Handle.Position = Vector3.new(-239.95, 1.5, -110.95)
    end
    if CSPAWN == 4 then
    game.Workspace.Maps.Concept["The concept suitcase!"].Handle.Position = Vector3.new(-335.3, 1.5, -60.8)
    end
    print(CSPAWN)
end

3 answers

Log in to vote
1
Answered by 7 years ago

I think I understand your point. Unless you randomize the seed the script will print the exact same number each time

You can do this by adding math.randomseed(tick())to the very beginning of your script and it should produce a random number each time you do math.random(4)

0
._. i don't think this is even the right topic m9, but your right :3 greatneil80 2647 — 7y
0
No it's right what are you saying. His number isn't randomizing and this is how you do it. User#9949 0 — 7y
Ad
Log in to vote
-1
Answered by 7 years ago

The reason the only reason its picking one, is its the only reason to pick! The first argument is the lowest number the value to get, and the second variable is the highest it can get.

0
accept my answer i posted it 2 minutes before greatneil80 hiimgoodpack 2009 — 7y
Log in to vote
-2
Answered by 7 years ago

well, the first one is SUPPOSED to be 1. i was talking about the variable CSPAWN. I tried your method on CSPAWN but it just does 0 now! Sorry I am kinda a beginner scripter

0
Edit your question instead of posting an answer. Also, can I see your math.random statement? hiimgoodpack 2009 — 7y
0
dude... Just say math.random(0,1) sheesh.. xD @0HappyManDudeGuyq greatneil80 2647 — 7y

Answer this question