So basically I am creating a script that surrounds the main part with other parts, only problem is the other parts are off to the side by a little:
OG part is a part as said by the name, SpaceApart is 5. and Rotate is 12.
for t = 0, amount, 1 do
-- set the po2
local Part = Createpart()
local weld = Instance.new('Weld')
weld.Parent = originPart
weld.Part0 = originPart
weld.Part1 = Part
-- set the position and stuff
local x = math.cos(math.rad(t) * (rotate / (t / t)))
local y = math.sin(math.rad(t) * (rotate / (t / t)))
weld.C1 = ogPart.CFrame * CFrame.new(x * spaceApart, y * spaceApart, 0)
end
Not sure why this is happening at all but here are my assumptions:
I tried doing this without X and Y. Its still offseted, meaning that even at the value being 0 its offseted. So its got nothing to do with the X and Y values.
Tell me what yalls think cause I have no idea what is going on
Don’t worry that was just for demonstration purposes
I believe the problem is that you are multiplying the position rather than adding them.
-- Old (from your example)
weld.C1 = ogPart.CFrame * CFrame.new(x * spaceApart, y * spaceApart, 0)
-- New
weld.C1 = ogPart.CFrame + CFrame.new(x * spaceApart, y * spaceApart, 0)
However, if you run into problems, just view my code or ask me a question; I don’t mind.
local amount = 20
local radius = 5
local subject = workspace.Part
for i = 0, amount do
local part = Instance.new("Part", subject)
part.Anchored = true
part.Size = Vector3.new(1, 1, 1)
part.Transparency = 0.5
local angle = (math.pi * 2 / amount) * i
-- Calculate the rotation matrix based on the subject's rotation
local rotationMatrix = CFrame.Angles(math.rad(subject.Rotation.x), math.rad(subject.Rotation.y), math.rad(subject.Rotation.z))
-- Calculate the position relative to the subject's rotation
local offset = Vector3.new(math.sin(angle) * radius, 0, math.cos(angle) * radius)
-- Apply the rotation matrix to the offset
local rotatedOffset = rotationMatrix:pointToWorldSpace(offset)
-- Set the part's position relative to the subject's position and rotation
part.Position = subject.Position + rotatedOffset
end
Please correct me if I’m incorrect, but I forgot to note that apparently you can’t add Cframes together. Change the Cframes to only contain their positional data (Vector3s) to resolve this.
Hmm. Could you please provide any further information about this script? Right now, I’m not really sure what “ogPart” implies. If at the very least you could provide the variable properties or the entire source. that would be extremely useful.
Also this is the create part function if you want it:
function Createpart()
local part = Instance.new(“Part”)
part.Anchored = false
part.Size = Vector3.new(1,1,1)
part.Parent = workspace
part.Transparency = 0.5
return part
end
By the way, why not just adjust the position instead of utilizing a weld if you don’t want the surrounding parts to align with the main part? The issue is presumably with the weld. To clarify this problem, we are adding twice the subject position to the weld part, which is already moving the components to the part you specified. This can probably be taken out and function.