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

Help with an offset thing?

Asked by 9 years ago

My offset script doesn't work. I have been trying to use print() to find out the magnitude but no luck.

for i = 1,  5 do
local barriers = {}
local separation = 20
local p = Vector3.new(math.random(-140,-110), workspace.Platform.Position.Y - num1/2 + 0.5, math.random(22,85))
local nearest = 100
for _, barrier in pairs(barriers) do
    nearest = (barrier - p).magnitude
print(nearest) --nothing appears here
end
if nearest > separation then
    table.insert(barriers, p)
--build offset stuff
end

1 answer

Log in to vote
0
Answered by 9 years ago

You're trying to loop through an empty table. Since the table is empty, the loop doesn't increment, since you're using pairs.

for i = 1,  5 do
local barriers = {} --empty table
local separation = 20
local p = Vector3.new(math.random(-140,-110), workspace.Platform.Position.Y - num1/2 + 0.5, math.random(22,85))
local nearest = 100
for _, barrier in pairs(barriers) do --the table is empty, so the loop doesn't run
    nearest = (barrier - p).magnitude
print(nearest) --nothing appears here
end
if nearest > separation then
    table.insert(barriers, p)
--build offset stuff
end

0
If you need help fixing it, then it would help if you described your goal with more detail. aquathorn321 858 — 9y
0
How would i combat this? connor12260311 383 — 9y
0
well, my goal is to randomly generate parts at least 20 studs away from each other, but the offset doesnt work. connor12260311 383 — 9y
Ad

Answer this question