I've been trying to make some constraint levers work for a few days now, they work fine and all except for the fact that the welding screws up and offsets the parts. (Screenshot below)
prntscr.com/dptvyp
Primary Weld Code
-- | Welds levers | -- Weld.WeldLever = function(Lever,CS,AS) -- Lever Model, Constraint Settings, Attachment Settings local Hinge = Constrain.Hinge(Lever,"Constraint",CS.LimitsEnabled,CS.UpperAngle,CS.LowerAngle,CS.Restitution,CS.ActuatorType,CS.AngularSpeed,CS.ServoMaxTorque,CS.TargetAngle) local A0 = Constrain.Attach(Lever.Joint0,Lever.Name.."Joint",AS.Position0,AS.Rotation0) local A1 = Constrain.Attach(Lever.Joint1,Lever.Name.."Joint",AS.Position1,AS.Rotation1) Hinge.Attachment0 = A0 Hinge.Attachment1 = A1 for i,p in next,(Lever:GetChildren()) do if (p.Name ~= "Joint0") and (p.Name ~= "Joint1") and (p:IsA("BasePart")) then Weld.NewWeld(Lever.Joint1,p,Lever.Joint1,p.Name.."Weld") end; end; for i,p in next,(Lever:GetChildren()) do if (p.Name ~= "Joint0") and (p:IsA("BasePart")) then p.Anchored = false p.CanCollide = false end; end; end;
Weld Generator :
-- | Creates new Welds | -- Weld.NewWeld = function(p0,p1,Parent,Name) local w = Instance.new("Weld") w.Part0,w.Part1 = p0,p1 w.C0 = p0.CFrame:inverse() w.C1 = p1.CFrame:inverse() w.Parent = Parent w.Name = Name return w end;
Constraint Service :
Strain.Hinge = function(Parent,Name,LE,UA,LA,Rest,AT,Ang,Tor,TAMA) --Parent, Name (String), Limits Enabled (Boolean), Upper Angle (Int), Lower Angle (Int), Restitution (Int), Actuator Type (String[Servo,Motor or None]), Angular (Int[Angular Speed/Angular Velocity]), Max Torque (Int), Target Angle/Max Acceleration (Int) local Hinge = Instance.new("HingeConstraint") Hinge.Parent = Parent Hinge.Name = Name if LE then Hinge.LimitsEnabled = true Hinge.UpperAngle = UA Hinge.LowerAngle = LA Hinge.Restitution = Rest end if AT == "Motor" then Hinge.ActuatorType = Enum.ActuatorType.Motor Hinge.AngularVelocity = Ang Hinge.MotorMaxTorque = Tor Hinge.MotorMaxAcceleration = TAMA elseif AT == "Servo" then Hinge.ActuatorType = Enum.ActuatorType.Servo Hinge.AngularSpeed = Ang Hinge.ServoMaxTorque = Tor Hinge.TargetAngle = TAMA else Hinge.ActuatorType = Enum.ActuatorType.None end return Hinge end;
Help is greatly appreciated!
--sending as discussed in game
local prev local parts = script.Parent:GetChildren() for i = 1,#parts do if (parts[i].className == "Part" or parts[i].className == "UnionOperation") then if (prev ~= nil)then local weld = Instance.new("Weld") weld.Part0 = prev weld.Part1 = parts[i] weld.C0 = prev.CFrame:inverse() weld.C1 = parts[i].CFrame:inverse() weld.Parent = prev end prev = parts[i] end end parts = script.Parent:GetChildren() for i=1,#parts do if (parts[i].className == "Part" or parts[i].className == "UnionOperation") then parts[i].Anchored = false end end wait() script:remove()