Hi. I am trying to make a train track building system (similar to Theme Park Tycoon 2’s roller coaster building system), but when I add a curved track piece it doesn’t position to the end part’s position in the train track before it & any track built after the curve will also be out of place. Also, I have end & start parts inside every track piece which point to where the end & starts of the track are. I used @inHeadspace 's solution in the Devforum post below to find the beginning & end of a part. Any ideas?
Finding The End Of A Part? - Scripting Support - Developer Forum | Roblox
My code is below:
script.Parent.RemoteEvent.OnServerEvent:Connect(function(plr) --Build button pressed
--For context, "curNode" is an obj value holding the currently selected node (track piece), "c" is a clone of "curNode" value to be the next node (track piece)
local splitted = string.split(script.Parent.Parent.Parent.CurNode.Value.Name, "Node_")
local c:UnionOperation = game.ReplicatedStorage.Track:FindFirstChild(script.Parent.Parent.Parent.CurType.Value):Clone()
local curNode:UnionOperation = script.Parent.Parent.Parent.CurNode.Value
if not script.Parent.Parent.Parent.CurNode.Value.Parent:FindFirstChild("Node_"..tonumber(splitted[2] + 1)) then
local CVector = (curNode.CFrame * CFrame.new(curNode.Size.X/2,0,0)).Position
local minusCVector = (curNode.CFrame * CFrame.new(-curNode.Size.X/2,0,0)).Position
curNode.Start.Position = minusCVector
curNode.End.Position = CVector
c.Parent = workspace.Coaster1
c.Name = "Node_"..tonumber(splitted[2] + 1)
c.Position = curNode.End.Position
c.Orientation = script.Parent.Parent.Parent.CurNode.Value.Orientation
wait(.2)
script.Parent.Parent.Parent.CurNode.Value = workspace.Coaster1:FindFirstChild("Node_"..tonumber(splitted[2] + 1))
game.ReplicatedStorage.Camera:FireClient(plr, script.Parent.Parent.Parent.CurNode.Value)
else
print("you already have track there!")
end
end)```