Long Truss Module - Make TrussParts longer than 64 studs!

This will only be useful to you if you are creating trusses through code (eg. procedural generation), so you will still have to make longer trusses the normal way, by duplicating them manually, if you are building.

Since TrussParts have a maximum height limit of 64, I created a module that allows for making longer trusses. I originally made this because I am making a game that involves a procedurally generated tower, and I am using trusses as ladders to connect levels. I ran into a problem, however, when the truss length was getting capped at 64. I made this module as an easy way to make trusses longer than 64.

Information:

  • It works by creating multiple TrussParts and stacking them together
  • Returns a model containing the TrussParts
  • Anchored by default (unless set in the Properties table)
  • If not anchored, WeldConstraints will be created between the TrussParts so that it behaves like one part
  • All part surfaces are set to smooth

How to use:

Requiring the module will return a function with 4 arguments:

  • Properties: a dictionary of properties to apply to all TrussParts that are created (eg. Color, Material, Transparency, etc.)
  • CFrame
  • Height: the height (Y value) of the truss
  • Parent: (optional) the parent of the resulting model

Get it here:

https://www.roblox.com/library/6967267607/Long-Truss-Module

Source Code:

local maxTrussHeight = 64
local surfaces = {"BackSurface", "BottomSurface", "FrontSurface", "LeftSurface", "RightSurface", "TopSurface"}
local smooth = Enum.SurfaceType.Smooth

return function(properties, cframe, totalHeight, parent)
	totalHeight = math.clamp(totalHeight, 2, 2048) -- 2048 is max part size
	local anchored = properties.Anchored == nil and true or properties.Anchored -- set to anchored by default
	local weldTogether = not anchored -- weld trusses if unanchored

	local trussAmount = math.ceil(totalHeight / maxTrussHeight)	-- number of trusses
	local lastTrussHeight = totalHeight - ((trussAmount - 1) * maxTrussHeight) -- height of the last truss (all others have a height of 64)

	-- Create a model
	local model = Instance.new("Model")
	model.Name = "Truss"

	-- Create truss parts
	local currentCFrame = cframe * CFrame.new(0, -totalHeight / 2, 0)
	local prevTruss
	for i = 1, trussAmount do
		-- Create TrussPart
		local truss = Instance.new("TrussPart")

		-- Set all surfaces to smooth
		for _, surface in pairs(surfaces) do
			truss[surface] = smooth
		end

		-- Set properties
		for property, value in pairs(properties) do
			truss[property] = value
		end

		truss.Name ..= i
		truss.Anchored = anchored

		-- Set Size and CFrame
		local height = i < trussAmount and 64 or lastTrussHeight
		truss.Size = Vector3.new(2, height, 2)
		truss.CFrame = currentCFrame * CFrame.new(0, height / 2, 0)

		currentCFrame *= CFrame.new(0, maxTrussHeight, 0)

		-- Weld trusses together
		if weldTogether and prevTruss then
			local weld = Instance.new("WeldConstraint")
			weld.Part0 = prevTruss
			weld.Part1 = truss
			weld.Parent = truss
		end

		truss.Parent = model
		prevTruss = truss
	end

	model.Parent = parent

	return model
end

If you find any bugs or have any suggestions, please tell me and I’ll try my best to fix/add them!

2 Likes

What’s the advantage of using this instead of simply duplicating a truss and moving it on top of the previous one?

2 Likes

Maybe it prevents lag but I’m not sure

That’s basically what it does, but it’s only for if you’re creating a truss through a script. I made it because I was trying to use trusses to connect levels in a game through code, but it wasn’t working because they were too long. Sorry I didn’t say that very well in my post