Setting the Y Value of a CFrame while keeping all the other values

The goal of the script is to spawn a part infront of the player on the ground. The line of code below is how I am attempting to do this.

clone.CFrame = CFrame.new(v.CFrame.X, -15.75, v.CFrame.Z) * CFrame.new(0, 0, -5)

“v” refers to the player’s HumanoidRootPart and “clone” is the part being spawned infront of the player. The first CFrame is supposed to set the position and orientation of the clone’s CFrame while the second one does the offset however this doesn’t include the orientation which makes the rest of the script basically pointless. I have tried to set the orientation but the only way I have managed to do it is by doing:

clone.CFrame = v.CFrame * CFrame.new(0, 0, -5)

but this doesn’t allow me to set the Y value of the CFrame to make the part appear on the ground.

You need to adjust the position aspect of the object’s CFrame too.

clone.CFrame = clone.CFrame * Vector3.new(0, (how many studs you want to move down), 0)

clone.CFrame = v.CFrame * CFrame.new(0, -3, -5)

clone.CFrame = v.CFrame + Vector3.new(0, 10, 0)

clone.CFrame = CFrame.new(v.CFrame.X, -15.75, v.CFrame.Z) * CFrame.fromEulerAnglesXYZ(angle1, angle2, angle3) * CFrame.new(0, 0, -5)

This is how the script currently works, I’m trying to make the gray part appear infront of the player rather than spawning to the side while still keeping it on the ground

This is the code that the script in the video is using:

clone.CFrame = CFrame.new(v.CFrame.X, -15.75, v.CFrame.Z) * CFrame.new(0, 0, -5)

clone.Position = Vector3.new(v.Position.X, -15.75, v.Position.Z) + v.CFrame.LookVector * 5 Forget about the trig, can you try this?

I tried it and it works! Thanks a bunch.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.