Help with advanced script

Hi everybody! So I’m currently developing a lightning system in which it’ll check the distance between an object hit (such as the ground) and the clouds, I want the script to be able to create attachments like in this image I attached, how would I achieve that? using a for loop? I believe it might take some math operations as well.
(the blocks are the starting and finishing distances and the circles are the attachments)
I want to keep the same attachments but extend them or shorten them

can you explain in greater detail on what you are trying to do since the example image you provided looks like is just squares with dots

Sure, you can use a loop.

You say you always want the same number of divisions?

local a = workspace.Start
local b = workspace.Target

for i = 1, 5 do
  local pos = a.Position:Lerp(b.Position, i / 6)
  print(pos)
end

yes, I want to distribute the attachments equally, they need to be a number and only vary in distance between each other

the blocks are the ground and the clouds, for example, and the dots are the attachments

this script uses raycasting so the distance may vary, thats why the second one looks smaller

can’t you just use raycast? its perfect for mesuring distance and stuff, for the attachment part just change the position every defined time

I did use raycast, the problem i had is i didnt know how to distribute the attachments equally through the distances

i havent checked it yet but about what i see divisions are what i should use, thanks

are you trying to create a ray tracer?

No, I have the ray tracer created, what I wanted to achieve is to make 5 attachments equally distributed between the distance of the clouds (starting ray) and the block detected

the attachments are the little dots you see in the image, and the squares are the distance between a cloud and the object hit by the ray

equally…huh well you can’t do that if its not even, you can use math.floor to round it to a even number do something like this

local function round_to_even(num: number): number
    return math.floor(num - num%2)
end

then use your new measure and do stuff with it

i mean i dont really care if its not even though, i just wanted to make sure they all have the same difference in distances so that the finishing attachment doesnt look 2 times longer than the others

well just make it add another one every period of time, thats the best i can think of

i never came up with divisions, and now that i think it its true i should use them for this

In my case, in the for loop i would create 5 attachments, but before that i’d get the magnitude of the clouds and the block hit, so i can know the distance, THEN i can divide, thanks!