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

Why wont it select the numbers from the table?

local Ran = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0, -1, -2, -3, -4, -5}

local r = Ran[(math.random(1, 15))]

Shot1.CFrame = Player.Character.Torso.CFrame*CFrame.new(r, r, r)-- CFrame Coordinates thingy
Shot2.CFrame = Player.Character.Torso.CFrame*CFrame.new(r, r, r)
Shot3.CFrame = Player.Character.Torso.CFrame*CFrame.new(r, r, r)
Shot4.CFrame = Player.Character.Torso.CFrame*CFrame.new(r, r, r)
Shot5.CFrame = Player.Character.Torso.CFrame*CFrame.new(r, r, r)
Shot6.CFrame = Player.Character.Torso.CFrame*CFrame.new(r, r, r)
Shot7.CFrame = Player.Character.Torso.CFrame*CFrame.new(r, r, r)
Shot8.CFrame = Player.Character.Torso.CFrame*CFrame.new(r, r, r)
Shot9.CFrame = Player.Character.Torso.CFrame*CFrame.new(r, r, r)
Shot10.CFrame = Player.Character.Torso.CFrame*CFrame.new(r, r, r)
Shot11.CFrame = Player.Character.Torso.CFrame*CFrame.new(r, r, r)
Shot12.CFrame = Player.Character.Torso.CFrame*CFrame.new(r, r, r)
Shot13.CFrame = Player.Character.Torso.CFrame*CFrame.new(r, r, r)
Shot14.CFrame = Player.Character.Torso.CFrame*CFrame.new(r, r, r)

This should randomly select a number from the table called Ran and insert it in the CFrame Coordinates thingy. But its not working and I dont know why.

3 comments

0

Please provide any output that is given and end the loop where you want it to.

0

No output is given

1

You have an extra set of parentheses on line 3. Try removing them.

1 answer

✓ Accepted answer

You have already defined "r" on line 3, this means that "r" will always be the same value. If you want a new value for each of these then you will need to replace all of the r's in the CFrame.new() sections to r() and make a new function that does this

local function r()
	return math.random(-5, 9) -- Returns a random number from -5 to 9
end

There was no need to write up a table of numbers for this. But incase in the future you may want to return something different, specific values, then here, you can use this

local function r()
	return Ran[math.random(#Ran)] -- No need to write (1, 15) because #Ran will give you the number 
end

1 comment

0

Do not forget line 3, extra paranthesis.

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