#making a train script and this happens...

1 messages · Page 1 of 1 (latest)

sand field
#
local speed = 20 
local nodesFolder = workspace:WaitForChild("TrackNodes")

local nodes = {}
for _, node in ipairs(nodesFolder:GetChildren()) do
    table.insert(nodes, node)
end

table.sort(nodes, function(a, b)
    return tonumber(a.Name:match("%d+")) < tonumber(b.Name:match("%d+"))
end)

local currentNodeIndex = 1

while true do
    local targetNode = nodes[currentNodeIndex]
    local direction = (targetNode.Position - train.PrimaryPart.Position).Unit
    local distance = (targetNode.Position - train.PrimaryPart.Position).Magnitude

    train:SetPrimaryPartCFrame(CFrame.lookAt(train.PrimaryPart.Position, targetNode.Position))

    local travelTime = distance / speed
    local startTime = tick()

    while tick() - startTime < travelTime do
        train:SetPrimaryPartCFrame(train.PrimaryPart.CFrame + direction * speed * (1/60))
        task.wait(1/60)
    end

    currentNodeIndex = currentNodeIndex + 1
    if currentNodeIndex > #nodes then
        currentNodeIndex = 1
    end
end
sand field
#

No

topaz shale
sand field
#

I tried and it wouldn’t move