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

math.random() always picking the number 1?

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

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)

2 comments

0

._. i don't think this is even the right topic m9, but your right :3

0

No it's right what are you saying. His number isn't randomizing and this is how you do it.

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.

1 comment

0

accept my answer i posted it 2 minutes before greatneil80

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

2 comments

0

Edit your question instead of posting an answer. Also, can I see your math.random statement?

0

dude... Just say math.random(0,1) sheesh.. xD @0HappyManDudeGuyq

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