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

Help with an offset thing?

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

✓ Accepted answer

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

3 comments

0

If you need help fixing it, then it would help if you described your goal with more detail.

0

How would i combat this?

0

well, my goal is to randomly generate parts at least 20 studs away from each other, but the offset doesnt work.

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