I’m trying to make a part hover around the player and eventually rotate around the player at a fixed height and distance. I’m trying to implement this by having a part attached to the player’s humanoidrootpart using a hinge constraint, and then the rotating part is attached to that other part using a weld constraint. My issue is that currently, the hinge constraint lets the center part rotate around the x axis, when I want to rotate around the y. I tried setting the center part orientation to align the x axis by rotating 90 around the z axis, but the hinge constraint seems to reset this rotation everytime. Here’s the code I’m using so far:
local OrbObject = Instance.new("Part")
OrbObject.Massless = true
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
OrbObject.CFrame = HumanoidRootPart.CFrame * CFrame.new(0,0,-9)
OrbObject.Parent = game.Workspace
OrbObject.Anchored = false
local OrbCenter = Instance.new("Part")
OrbCenter.Massless = true
OrbCenter.CFrame = HumanoidRootPart.CFrame
OrbCenter.Orientation = Vector3.new(0,0,90)
OrbCenter.Anchored = false
OrbCenter.Parent = game.Workspace
OrbCenter.Size = Vector3.new(2,1,3)
OrbCenter.CanCollide = false
self.OrbObject = OrbObject
self.OrbCenter = OrbCenter
self.Player = Player
self.OrbConstraint = Instance.new("WeldConstraint")
self.OrbConstraint.Part0 = self.OrbCenter
self.OrbConstraint.Part1 = self.OrbObject
self.OrbConstraint.Parent = self.OrbCenter
self.OrbConstraint.Enabled = true
local Attachment0 = Instance.new("Attachment")
Attachment0.Parent = OrbCenter
Attachment0.Name = "Attachment"
local Attachment1 = Instance.new("Attachment")
Attachment1.Parent = HumanoidRootPart
Attachment1.Name = "Attachment"
local CenterHinge = Instance.new("HingeConstraint")
CenterHinge.Attachment1 = Attachment0
CenterHinge.Attachment0 = Attachment1
CenterHinge.Parent = OrbCenter