local roadParts = SS:WaitForChild("RoadParts")
local partsAmount = 5
for i=1,partsAmount,1 do
-- if i==1 then places the start of the road
if i==1 then
start = roadParts.StartFinish.Start:Clone()
start.Parent = workspace.Road
start.Name = tostring(i)
start.Short_Straight.CFrame = CFrame.new(0,1,0)
continue
end
-- Takes all the parts available and put them in a table to assign them a number
parts=roadParts:GetChildren()
partsArray = {}
for i=1, #parts, 1 do
if parts[i]:IsA("Model") then
table.insert(partsArray, parts[i])
end
end
-- Chooses a random road part
chosenPart = partsArray[math.random(1,#partsArray)]
-- Clones it and gives it a name
clone = chosenPart:Clone()
clone.Parent = workspace.Road
clone.Name = tostring(i)
previousRoadPart = workspace.Road:FindFirstChild(tostring(i-1)):FindFirstChildOfClass("MeshPart")
-- Takes the CFrame of the previously spawned road part
referenceCframe = previousRoadPart.After.WorldCFrame.Position
-- Makes the new road part CFrame the same of the previous one plus the difference between the center and the Before point of the mesh
newCFrameVector3= referenceCframe + (clone:FindFirstChildOfClass("MeshPart").CFrame.Position - clone:FindFirstChildOfClass("MeshPart").Before.WorldCFrame.Position)
-- Applies the new CFrame
clone:FindFirstChildOfClass("MeshPart").CFrame = CFrame.new(newCFrameVector3)
end```
#Help with CFrames
1 messages · Page 1 of 1 (latest)