[SOLVED] Part is flipping sideways when trying to configure CFrame with Script

I’m trying to make it so that it does not flip sideways, since I want to to lie flat on the ground. However, when I’m scripting it, and configure the CFrame with the script, it somehow flips sideways when playtesting it… I’m pretty novice in coding, but i’ve tried to like set different cframes and play around with it.

This is the current script that I have, it semi-works; it puts it in the right position when its needs to be, but is flipped sideways.

-- Variables
local ButtonPart = script.Parent
local BasePart = game.Workspace.TycoonOne.SectionOne.LightingBasePart
local basePartPosition00 = CFrame.new(-35.12, -21.635, -100.865)
local ButtonPartPosition00 = CFrame.new(-35.12, -21.595, -100.865)
local basePartPosition01 = CFrame.new(-35.12, 2.075, -100.865)
local ButtonPartPosition01 = CFrame.new(-35.12, 2.085, -100.865)
local StartDiggingOwned = game.ReplicatedStorage.StartDiggingSectionOneOwned
local LightingOwned = game.ReplicatedStorage.LightingSectionOneOwned

--CFrame positioning loop
while wait() do
	if StartDiggingOwned.Value == 1 and LightingOwned.Value == 0 then
-- Previous item owned but current item not owned
		ButtonPart.CFrame = ButtonPartPosition01
		BasePart.CFrame = basePartPosition01
		elseif StartDiggingOwned.Value == 0 and LightingOwned.Value == 0 the
-- None of the needed items owned
		ButtonPart.CFrame = ButtonPartPosition00
		BasePart.CFrame = basePartPosition00
	end
end

Thanks,
BurgerLord


image

1 Like

You should use CFrame.Angles

Multiply each CFrame value by CFrame.Angles(math.rad(90), 0, 0). That modifies the rotation part of the CFrame, so it will be rotated by 90 degrees on the X-axis. I had to wrap it in math.rad(0) because the angle values in CFrame.Angles are expected to be radians. You could also just as easily do this: CFrame.Angles(math.pi / 2, 0, 0), but it’s usually better for readability to use an angle in degrees and convert it later.

1 Like

Would I do for example

local ButtonPartPosition01 = CFrame.new(-35.12, 2.085, -100.865) * CFrame.Angles(math.rad(90), 0, 0)

?

Sorry for what would most likely be a simple question to you, but im pretty new to CFrame. :slight_smile:

Yes, that’s perfect. Also a quick tip for CFrames: Keep in mind that rotations are applied in a specific order. There are several different functions for rotating CFrames because of this, so if you need to rotate more specifically (like 30 degrees on the X, and 60 on the Y) pay attention to which order you want the rotations in.

1 Like

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