Parts position is not setting as intended

Hi, I am making a mirror and I want all the parts position correctly, I am not using viewport frames.
Here’s the code:

local World = workspace.World

local runService = game:GetService("RunService");

for i, v in pairs(World:GetChildren()) do
    if v:IsA("Part") then
        local clone = v:Clone();
        clone.Parent = workspace.ImaginaryWorld
        local mag = (v.Position.Z - workspace.Window.Position.Z )
        clone.CFrame = World[clone.Name].CFrame + Vector3.new(0, 0, -mag)
    end
end

To make something like a mirror world, you will probably have to get the Inverse CFrame of each and every object from the mirror & then place it in the same way but in the Opposite direction. Not really sure, but I believe its something like this.

I am gonna try that. Thank you!

1 Like

It doesn’t work. Any other solution?

Hm, I am pretty sure it should work, can you give your code here?

Sure, here you go:

local World = workspace.World

local runService = game:GetService("RunService");

for i, v in pairs(World:GetChildren()) do
    if v:IsA("Part") then
        local clone = v:Clone();
        clone.Parent = workspace.ImaginaryWorld
        clone.CFrame = clone.CFrame:Inverse()
    end
end

Okay, so after a bit research & some coding in my studio, I figgured out the solution to your problem :slight_smile: (I hope)

So what I did is basically wrote some code like this:

local Mirror = game.Workspace.Mirror --Basically my mirror part
local Testing = game.Workspace.Testing --Just a test part to clone

local newTesting = Testing:Clone() --the copy part 
newTesting.Parent = game.Workspace

local mirrorCF = Mirror.CFrame --Mirror's CFrame
local copyCF = mirrorCF:Inverse() * Testing.CFrame --Got Inverse CFrame to get relative position from Mirror to the Original part

newTesting.CFrame = mirrorCF * CFrame.new(copyCF.X, copyCF.Y, copyCF.Z*-1) --Then I just multiplied Z axis with -1 to flip the Position basically, you might want to multiply it with X axis depending on your mirror alignment

So you can get an idea of how you will do it from the code I have written above, this might not be the easiest way to do it, but it works out :slight_smile:

How it looked after running the above code:
https://gyazo.com/8216fd90515256a787bbc11d2eafc31e

The big part in the middle is basically my mirror…and the left side is the cloned one :slight_smile:

Oh, thank you very very very very much!

1 Like

Its alright, I believe we both learnt something new today lol

Idk why everytime it comes to math then I have no idea what to do I wish I was like others that finds the way to do it

local World = workspace.World

local runService = game:GetService("RunService");

for i, v in pairs(World:GetChildren()) do
    if v:IsA("Part") then
        local clone = v:Clone();
        clone.Parent = workspace.ImaginaryWorld
        local mag = (v.Position.Z - workspace.Window.Position.Z )
        clone.CFrame = World[clone.Name].CFrame * CFrame.new(0, 0, -mag)
    end
end
1 Like

Actually yeah, thats much simpler form of it, I believe

I already tried the magnitude thing but that didn’t work

1 Like

This is easiest solution tho.

local World = workspace.World

for i, v in pairs(World:GetChildren()) do
	if v:IsA("Part") then
		local clone = v:Clone();
		clone.Parent = workspace.ImaginaryWorld
		clone.Anchored = true
		local mag = script.Parent.CFrame:Inverse() * v.CFrame
		clone.CFrame =  script.Parent.CFrame * CFrame.new(mag.X, mag.Y, -mag.Z)
	end
end

Yeah, but I meant like you gave the whole code to him, so it was easier for him I guess :slightly_smiling_face:

Also that is what my solution did too

Yup ik. But that *-1 is confusing in ur solution ^^.

1 Like

Oh, yeah. I just like doing it like that :stuck_out_tongue:

I should come back when ur not active bringing solutions for people <3 .

1 Like