I need help with road placement

Hello everyone!
I am working on a game about infrastructure and I can’t get the road placement working.
My idea is to work like this: Click on a city, then click to another city and it calculates how much that roads costs to build. Could anyone help me?

I’ve been looking on the internet for a long time to find the answer.

Let’s first set up the problem mathematically:

We need to know:
-The distance between two cities
-Length of a tile
-Price of a tile

Knowing the length of a road tile, we can divide the distance from city A to city B between the length of each tile. This will give us how many tiles we’ll need! Finally, all weneed to do is multiply the number of tiles we just calculated times the price of a single tile for the total price.

local tilePrice = 50 --Whatever price a tile is
local tileLength = 10 --Whatever length a tile is
local cityAPosition = Vector3.new() --Whatever position city A has
local cityBPosition = Vector3.new() --Whatever position city B has

local distance = (cityBPosition - cityAPosition).Magnitude --Distance between them
local tileCount = distance / tileLength --How many tiles we'll need to reach
local totalPrice = tileCount * tilePrice

Hope this helps!

Thanks! This is what I was looking for.