I’m trying to utilize a modular script to produce constraint objects, and am trying to pass Attachment points and the parent to the module via a server script.
Upon using the function, I receive this error:
This is the offending function in the module:
GenerateAlignment()
function AITConstraintModule.GenerateAlignment(Attach1,Attach2,Parent)
local Align = Instance.new("AlignOrientation")
Align.Mode = Enum.OrientationAlignmentMode.TwoAttachment
Align.AlignType = Enum.AlignType.Parallel
Align.PrimaryAxisOnly = false
Align.ReactionTorqueEnabled = true
Align.RigidityEnabled = true
Align.Responsiveness = 30
Align.Parent = Parent
Align.Attachment0 = Attach1
Align.Attachment1 = Attach2
end
And in the script calling GenerateAlignment()
GenerateTraffic()
local function GenerateTraffic()
ChooseVehicle()
ChooseLane()
local ClonedVehicle = RandomVehicleSelection:Clone()
ClonedVehicle.Name = "AIVehicle"
local CVehicleAttachment = ClonedVehicle.Attachment
local LaneAttachment = RandomLaneSelection.Attachment
ConstraintModule:GenerateAlignment(CVehicleAttachment,LaneAttachment,ClonedVehicle)
ClonedVehicle.CFrame = CFrame.new(LanePosition)
ClonedVehicle.Parent = TrafficFolder
PhysicsService:SetPartCollisionGroup(ClonedVehicle, "RaceCars")
wait(.5)
ClonedVehicle.LinearVelocity.MaxForce = 100000
if RandomLaneSelection.Name == "Pass" then
ClonedVehicle.LinearVelocity.LineVelocity = 85
else
ClonedVehicle.LinearVelocity.LineVelocity = 70
end
ClonedVehicle.Rev.PlaybackSpeed = random:NextNumber(0.6,0.9)
ClonedVehicle.Rev:Play()
ClonedVehicle.LinearVelocity.Enabled = true
end
ClonedVehicle.Attachment and RandomLaneSelection.Attachment both exist, and ClonedVehicle refers to a car that has been duplicated and placed into a specific folder in Workspace. The code inside the GenerateAlignment function has simply just been moved out of the server script and placed into a module format. This did work as intended in its original format, but I wanted to pretty GenerateTraffic() up a little while also utilizing this constraint generator elsewhere.
I don’t understand where the module is finding a table, though.
Any help is appreciated.