So I recently made joints that attach to a part, and by pressing T the selected joint rotates clockwise and sets the NEW joint as the PrimaryPart (allowing for the model to be re-positioned accordingly)
So the problem with my code is that it's super inefficient (it simply guesses the CFrame based on the variable number
Any suggestions on how to improve the code would be appreciated, and more of the code (if necessary) will be provided
Code (give me a break it's summer and I know it looks ugly):
local function GetClockwiseJoint()
local target = Mouse.Target
if target == nil or target.Name ~= 'Joint' then return end
local j = SetJoint
local cfx, cfy, cfz = j.Position.x, j.Position.y, j.Position.z
local newpos
if number == 1 then
newpos = vec(cfx - 4, cfy, cfz + 4)
elseif number == 2 then
newpos = vec(cfx - 4, cfy, cfz - 4)
elseif number == 3 then
newpos = vec(cfx + 4, cfy, cfz - 4)
elseif number == 4 then
newpos = vec(cfx + 4, cfy, cfz + 4)
number = 0
end
number = number + 1
for nm, prt in pairs(Joints) do
if prt.Position == newpos then
SetJoint = prt
UpdateJointPosition(SetJoint, target) --Updates the position accordingly
end
end
end
