For me as well, I could give up on this. Generate is really good, there is another way like to make roads realistic, highways, transportations tunnels, etc?
fixed the module; theres a limit of 617 roads, more than this and roblox breaks
--[[
RoadGenerator
Open-sourced script created by MrSprinkleToes
Updated by Tob_Coline
This version was changed on 7/22/2024.
--]]
local module = {}
local roadData = require(script.RoadData).Data
-- everything below this comment may break if you aren't sure what you're doing, so be careful!
-- if you think you probably know what you're doing, feel free to mess around with it!
function module.generateRoads(colorRoads, drawPoints, roadWidth)
-- make sure all vars have values
colorRoads = colorRoads or false -- default value false
drawPoints = drawPoints or false -- default value false
roadWidth = roadWidth or 5 -- default value 5
local scaleMultiplier = 10000 -- must keep value at 10000
local tbl = game:GetService("HttpService"):JSONDecode(roadData)
local roadColors = {}
local f = false
local function num(model)
local amount = 0
for _,thing in pairs(model:GetChildren()) do
amount = amount + 1
end
return amount
end
local function genRoad(number)
local roads = Instance.new("Model", workspace)
local road = tbl["features"][number]
local properties = road["properties"]
local roadname = properties["name"] or properties["official_name"] or "Unknown"
local coordinates = road["geometry"]["coordinates"]
-- set road color
if colorRoads then
roadColors[roadname] = Color3.fromRGB(math.random(0,255),math.random(0,255),math.random(0,255))
end
-- set road name
roads.Name = roadname or properties["alt_name"] or "Unknown"
local count = 1
-- create & name each point of the road in the correct order
for _,coordinate in pairs(coordinates) do
local x = coordinate[1]
local z = coordinate[2]
local p = Instance.new("Part", roads)
p.Size = Vector3.new(.5,.5,.5)
p.Anchored = true
p.Position = Vector3.new(x * scaleMultiplier, 0, z * scaleMultiplier)
p.Name = count
p.Material = Enum.Material.Neon
p.Color = roadColors[roadname] or Color3.fromRGB(163, 162, 165)
roads.PrimaryPart = p
count = count + 1
end
return roads
end
local function drawRoad(model)
local current = 1
-- for each point in the road
for i = 1, #model:GetChildren() do
-- if there is a point after the current point
if model:FindFirstChild(current+1) then
local p = Instance.new("Part", model)
p.Anchored = true
p.Material = Enum.Material.SmoothPlastic
if colorRoads then
p.Color = model:FindFirstChild(current).Color
else
p.Color = Color3.fromRGB(27, 42, 53)
end
-- draw a part between the current & next point in the road
local p1 = model:FindFirstChild(current).Position
local p2 = model:FindFirstChild(current+1).Position
local part = p
part.CFrame = CFrame.fromMatrix((p1+p2)/2,(p2-p1).Unit,Vector3.new(0,1,0),- Vector3.new(0,1,0):Cross((p2-p1).Unit))
part.Size = Vector3.new((p2-p1).Magnitude,.25,.5)
-- make the current & next points invisible if not drawing points
if not drawPoints then
model:FindFirstChild(current).Transparency = 1
model:FindFirstChild(current+1).Transparency = 1
end
end
current = current + 1
end
end
local function combineandteleport()
local roads = Instance.new("Model", workspace)
roads.Name = "Roads"
local f = false
for _, object in pairs(workspace:GetChildren()) do
if object:IsA("Model") and object ~= roads then
object.Parent = roads
end
end
wait(5)
roads:PivotTo(CFrame.new(0,0,0))
roads:ScaleTo(roadWidth)
end
local MaxRoads = #tbl["features"]
if MaxRoads > 610 then
MaxRoads = 610
end
-- limit of 617 roads, more than this and roblox breaks
for i=1, MaxRoads do
local road = genRoad(i)
drawRoad(road)
end
combineandteleport()
warn("Roads generated!")
end
return module