Keeping Rotation With Weld

I’m making models (different fruits) weld onto a chopping board model inside my character. I replicated their position from the original chopping board onto this cloned one using a replica of what it should look like inside of ServerStorage. How would I also calculate the angle to rotate the fruits correctly while using a weld?

CFruit is a model on the chopping board in Workspace
SFruit is a model on the chopping board in ServerStorage (the example board I’m replicating)
SChopping is the chopping board in ServerStorage

Here is what has been so far successful for one of the fruits, but the banana gets flipped upside down, so I’m having trouble finding the true calculations.

local CFruit = SFruit:Clone()
	
WeldModel(CFruit) --Welds it together if there are multiple parts.

local X, Y, Z = SFruit.PrimaryPart.CFrame:ToEulerAnglesXYZ() --Gets the original angle
	
CFruit.Parent = ChoppingBoard:WaitForChild("Fruits")
CFruit.PrimaryPart.CFrame = ChoppingBoard:WaitForChild("Board").CFrame * CFrame.Angles(X, Y, Z) --idk if the weld overwrites, probably does
	
SetVisibility(CFruit, 0) --make it visible
	
CFruit.PrimaryPart.Anchored = false
	
local Weld = Instance.new("Weld")
	
Weld.Part0 = ChoppingBoard:WaitForChild("Board")
Weld.Part1 = CFruit.PrimaryPart
	
local X1, Y1, Z1 = SFruit.PrimaryPart.CFrame:ToEulerAnglesXYZ() --gets the original angle (on server example)
local X2, Y2, Z2 = SChopping.PrimaryPart.CFrame:ToEulerAnglesXYZ() --gets the original chopping board angle (on server example)

local Difference = CFrame.new(SChopping.Board.Position - SChopping.Fruits[Fruit.Parent.Name].PrimaryPart.Position) * CFrame.Angles(X2 - X1, Y2 - Y1, (Z2 - Z1) * math.rad(180)) --Gets the difference in the position and then tries to in the angles. The board was rotated 180 degrees on the Z axis as well.
	
Weld.C0 = Difference
Weld.Parent = CFruit

Here’s what I’m trying to accomplish:

Here’s what happens:

4 Likes

CFrame before you weld the fruit

I have, on the 8th line of the code I posted.

1 Like

WeldModel(CFruit) --Welds it together if there are multiple parts.

local X, Y, Z = SFruit.PrimaryPart.CFrame:ToEulerAnglesXYZ() --Gets the original angle
	
CFruit.Parent = ChoppingBoard:WaitForChild("Fruits")
CFruit.PrimaryPart.CFrame = ChoppingBoard

WeldModel has come first then you CFramed it CFrame first then Weld it.

Edit: Misunderstood let me re read. :slight_smile:

4 up from the bottom line of that script, Im no good in math or CFrames but try setting 180 to 0

Nope.

1 Like

What about making the number 360?

The reason for me applying the 180 roatation was because that’s what I did to the board when welding it to my character. I’m not sure if this is how I even do it, it’s just an attempt.

happens3

1 Like

Make it 90 degrees? All I can say is play with the numbers possibly, Im not on my pc rn so I cant test anything out, sorry. :frowning:

Still, doesn’t work. I’ve played around and it works for some of the fruits, but not the others. I want to find a solution that will work for all fruits for easy configuration later on.

1 Like

So what you can do is save the orientation of your fruit to the chopping board on initialization.
Like if your SFruit is already oriented correctly to SChopping, you can save it using this method:

local newCFrame = SChopping.Board.CFrame:Inverse() * SFruit.PrimaryPart.CFrame

Then you can set the C0 of the Weld between the real chopping board and fruit to newCFrame:

Weld.C0 = newCFrame

How you store this CFrame is up to you.
I may also be wrong, but I’m pretty sure this is the answer if you already have it all set up.

2 Likes

I have used this code and it ends up like this:

I changed it to C1 and it was just an arch over the top of the board.

1 Like

Try switching around the CFrames, and setting that to C0:

SFruit.PrimaryPart.CFrame:Inverse() * SChopping.Board.CFrame
2 Likes

This looks like exactly what happened when setting the code before to C1.

1 Like

Could it be that you could be holding the chopping board upside-down? Because it looks like that’s what’s happening. It would make a lot of sense too actually.

Try just flipping SChopping in server storage upside-down and try again with my original suggestion.

2 Likes

I did rotate it 180 degrees on the Z axis when welding it to me. I used the original code and flipped the board upside-down with the same result.

Edit 2: I removed the items from the board and rotated the board around a little bit to match the weld. Worked perfectly!

Edit: Here is the code used to weld the board to me

local NewWeld = Instance.new("Weld")

NewWeld.Parent = NewBoard
NewWeld.Name = "BoardtoTorso"
NewWeld.Part1 = NewBoard.PrimaryPart
NewWeld.Part0 = Character:WaitForChild("UpperTorso")
NewWeld.C1 = CFrame.new(0, .5, 2.5) * CFrame.Angles(0, 0, math.rad(180))
2 Likes

Since you are welding the board to the character, try just rotating the board on the X axis I guess. If that doesn’t work, try the Y axis:


NewWeld.C1 = CFrame.new(0, .5, 2.5) * CFrame.Angles(math.rad(180), 0, math.rad(180))

Also out of curiosity, why did you rotate the board on the Z axis?

1 Like

I like the way the board is currently welded. It was rotated because I wanted the board to be flipped the correct way. There’s a hole on the left side, but when I originally welded it, the hole was on the right. Therefore, I rotated it 180 degrees on the Z axis.

2 Likes

My guess is that you need to rotate the board on one of the other axes to orient it correctly, because the board was flipped upside-down while getting the hole on the right side.
Try flipping the board on the Y-axis instead:


NewWeld.C1 = CFrame.new(0, .5, 2.5) * CFrame.Angles(0,math.rad(180),0)

2 Likes