#Train Problem: Not moving

1 messages · Page 1 of 1 (latest)

viscid venture
#
local Speed = 20

for i, folder in ipairs(workspace.TrainTest.Path:GetChildren()) do
    local Positions = {}
    for i, parts in ipairs(folder:GetChildren()) do
        Positions[tonumber(parts.Name)] = parts.Position
        parts:Destroy()
    end
    local TotalDistance = 0
    local CFrames = {}
    for i = 1, #Positions do
        local PreviousI = i - 1
        if PreviousI == 0 then PreviousI = #Positions end
        local Offset = Positions[i] - Positions[PreviousI]
        CFrames[i] = CFrame.lookAt(Positions[i], Positions[i] + Offset)
        local Part = Instance.new("Part")
        Part.Anchored = true
        Part.CanCollide = false
        Part.CanTouch = false
        Part.CFrame = CFrames[i] * CFrame.fromOrientation(0, math.pi / 2, 0)
        Part.Position -= Offset * 0.5
        Part.Size = Vector3.new(Offset.Magnitude, 0.5, 0.5)
        Part.Shape = Enum.PartType.Cylinder
        Part.Color = Color3.new(0.1, 0.1, 0.1)
        Part.TopSurface = Enum.SurfaceType.Smooth
        Part.BottomSurface = Enum.SurfaceType.Smooth
        Part.Parent = folder
        TotalDistance += Offset.Magnitude
    end
    local StartCFrame = CFrame.lookAt(Positions[1], Positions[2])
    local Amount = math.round(TotalDistance / 100)
    local WaitTime = TotalDistance / Amount / Speed
    local Targets = {}
    for i = 1, 1 do
        local Target = Instance.new("Part")
        Target.Anchored = true
        Target.CanCollide = false
        Target.CanTouch = false
        Target.CFrame = StartCFrame
        Target.Size = Vector3.new(0,0,0)
#
Target.Transparency = 1
        Target.Parent = folder
        local Attachment1 = Instance.new("Attachment", Target)
        local Model = game.ServerStorage.Models[folder.Name]:Clone()
        Model:SetPrimaryPartCFrame(StartCFrame)
        Model.Parent = folder
        local Attachment0 = Instance.new("Attachment", Model.PrimaryPart)
        local AlignPosition = Instance.new("AlignPosition")
        AlignPosition.Attachment0 = Attachment0
        AlignPosition.Attachment1 = Attachment1
        AlignPosition.MaxForce = math.huge
        AlignPosition.MaxVelocity = Speed
        AlignPosition.Responsiveness = 200
        AlignPosition.Parent = folder
        local AlignOrientation = Instance.new("AlignOrientation")
        AlignOrientation.Attachment0 = Attachment0
        AlignOrientation.Attachment1 = Attachment1
        AlignOrientation.MaxTorque = math.huge
        AlignOrientation.MaxAngularVelocity = 5
        AlignOrientation.Responsiveness = 10
        AlignOrientation.Parent = folder
        table.insert(Targets, Target)
    end
    spawn(function()
        wait(5)
        local i = 1
        while true do
            local NextI = i + 1
            if NextI > #Positions then NextI = 1 end
            local Magnitude = (Positions[NextI] - Positions[i]).Magnitude
            i = NextI
            spawn(function()
                for i, Target in ipairs(Targets) do
                    Target.CFrame = CFrames[NextI]
                    wait(WaitTime)
                end
            end)
            wait(Magnitude / Speed)
        end
    end)
end
#

Fixed the problem, I've removed the WeldConstraints and added Welds instead.

viscid venture
#

I'm still seeking help for this problem ^

reef jackal
#

Only reason I can think of that WeldConstraints wouldn't work where Welds do is that you're welding to something anchored on the first approach and not in the latter, that's the only circumstance under which a WeldConstraint will freeze an assembly

reef jackal
#

i.e. toggle Massless type drip...

viscid venture
reef jackal
#

I would anchor the assembly until you setup the WeldConstraint between the traincar thing and the pathing part

#

You could use ToObjectSpace to get what the offset for the traincar should be relative to the pathing part's cframe