I can't seem to position this properly

So I have a script that welds 5 parts around a base part in a circular form. The base part has a BodyPosition that follows the characters torso. Im trying to make it so that that the base part is always facing the look vector of the torso —as well as make its Z rotate to give the impression of the 5 welded parts orbiting around the base part.-- ALSO doesn’t seem to work when I put the body position into play. It just goes wild.
As you can see I’ve made quite a few attempts, but tbh im stuck

bp and bg = BodyPosition and bodygyro

for i, v in pairs (orbit) do
	local num = #orbit
	v.Weld.C0 = v.Weld.C0 * CFrame.Angles(0, 0, math.rad(360/num*i)) * CFrame.new(dist, 0, 1.5)--This sets the 5 parts around the base part
	coroutine.resume(coroutine.create(function()
		while char["Humanoid"].Health > 0 do game:GetService("RunService").RenderStepped:Wait()
			--incr = incr + speed
			local pos = base.CFrame
			bg.CFrame = bg.CFrame * CFrame.Angles(0, 0, .01) -- By leaving just this it rotates properly, but when I add back the bodyposition and body gyro (to make the base part face look vector), it just messes up.
			--base.CFrame = base.CFrame * CFrame.new(hrp.CFrame.p, hrp.CFrame.lookVector)
			--bg.CFrame = pos * CFrame.new(hrp.CFrame.p, hrp.CFrame.p + hrp.CFrame.lookVector) * CFrame.Angles(0, 0, .01)
			--v.CFrame = base.CFrame * CFrame.Angles(0, 0,math.rad(360/num*i+incr)) * CFrame.new(dist, 0, 1.5)
			--bg.CFrame = CFrame.new(torso.CFrame.p, torso.CFrame.p + char.HumanoidRootPart.CFrame.lookVector)
			--bp.position = torso.Position
		end	
	end))
end;
1 Like

Well to make it more basic. I have 1 part with BodyPosition positioned to my root part. How would I make it so it rotates as well as facing my root parts lookvector? + having BodyPosition

1 Like

It seems like the conflict is between these two lines (sorry idk how to put script block. Op is from default script block)

base.CFrame = base.CFrame * CFrame.new(0, 0, .1)
bg.CFrame = CFrame.new(hrp.CFrame.p, hrp.CFrame.p + char.HumanoidRootPart.CFrame.lookVector)

It seems like these two lines being in a loop contradict each other. Ik the second line constantly sets the CFrame of the gyro to make it face towards root parts look vector. How would I add onto this line to make it rotate as well?

1 Like

If people still don’t understand (tryna make this as basic as possible)

How do I keep the rotation of something while its pointed towards somewhere w/ look vector.

What is ‘bg’? Body Gyro?

I recommend simplifying and separating responsibility when it comes to CFrames as it helps to to debug them.

local dt = game:GetService("RunService").RenderStepped:Wait()

local hrp = char.HumanoidRootPart
local pos = hrp.Position
local dir =  (hrp.CFrame.LookVector * 999)
Rotation = Rotation and Rotation + 90 * dt or 0
--multiply by 'dt' (Delta time) to rotate 90degrees per second consistently, regardless of FPS.

local cf = CFrame.new(
    pos, 
    pos + dir
) * CFrame.Angles(0,0, Rotation)

by.CFrame = cf
---If this is a BodyGyro and still doesn't work, try setting the wild parts CFrame instead.

By the way, Code blocks are created with 3 (`} to open and close the block.

1 Like

WOOO IT WORKS. Thank you soo much!
Btw can you explain the code and how it turned out like that? I’m really bad with positioning and idk how to merge those.

Btw, why is it when I localize the Rotation it doesn’t work?

@WingItMan
I didn’t realize that RenderStepped didn’t work in server scripts and now to rotation is very laggy. I just heard about tween service, how might I implement that to the code?