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

Why wont it select the numbers from the table?

Asked by
neoG457 315 Moderation Voter
8 years ago
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.

0
Please provide any output that is given and end the loop where you want it to. FearMeIAmLag 1161 — 8y
0
No output is given neoG457 315 — 8y
1
You have an extra set of parentheses on line 3. Try removing them. Perci1 4988 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

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
0
Do not forget line 3, extra paranthesis. fireboltofdeath 635 — 8y
Ad

Answer this question