How to make sure that when a part reaches its specific orientation then it triggers an example event

i made a part that rotates when holding E or R key, i want to make it like when it reaches a specific orientation then something triggers,i have tried so many ways but it still dont work.

1 Like

Could you show your current code?

connect to a get property changed signal event and check the cframe orientation each time the cframe changes

:GetPropertyChangedSignal doesn’t fire for CFrames. I would suggest using RunService.Stepped instead.

thank you for correcting me :smile: i didnt even know that!

1 Like

local part1 = game.Workspace.Part1
local part2 = game.Workspace.Part2

local targetOrientation = CFrame.new(0, 0, 0)

local function checkOrientation()
local part2Orientation = part2.CFrame:pointToWorldSpace(part2.Position)
if (part2Orientation - targetOrientation).magnitude < 0.1 then
part2:Destroy()
end
end

game:GetService(“RunService”).RenderStepped:Connect(checkOrientation)

i tried many attempts this is what i have for now

what about the .Orientation property is that any help? your target orientation is 0,0,0 XYZ coordinates if im correct, you never specified a rotation in that variable

uhh i didnt get what you said you mean i didnt mention a specific value of orientation?

just try using the .Orientation property, it is a vector3 and is in degrees

so you want me change this line to vector3.new ?
local targetOrientation = CFrame.new(0, 0, 0)

Cframe.new(0,0,0) specifies a position, the rotation is after the coordinates, meaning that that will just set to the defualt rotation

if you dont mind can you correct the script for me please.

yes and the check is much simpler ==

local part1 = game.Workspace.sanka2.blonka2
local part2 = game.Workspace.RotatingModel
local bomb = game:GetService(“RunService”)

local targetOrientation = Vector3.new(0.442, 180, 180)

local function checkOrientation()
local part2Orientation = part1.CFrame:pointToWorldSpace(part1.Position)
if part2Orientation == targetOrientation then
part2:Destroy()
end
end

bomb.RenderStepped:Connect(checkOrientation)

i changed it a bit but it still not working, btw is this not supposed to be placed in local script?

You can use a local script if you only want it to show to one player. Just make sure the local script is parented in either StarterPlayer.StarterPlayerScripts or StarterGui.

Change part2Orientation to part2.Orientation

local part2Orientation = part2.Orientation


still not working though, basically the thing i wanna do is, see the part thats rotating? its me controlling with keys, and when it reaches the targetorientation that part beside the rotating part gets destroyed.

earrape :skull_and_crossbones::skull_and_crossbones::skull_and_crossbones: what you’re looking for is Vector3:Dot(), which returns a decimal between 1 and -1 depending on how similar both orientations are to one another. (1 is that the orientations face the exact same direction, -1 is the opposite.) get the orientation of the red part, and your goal orientation you want it to be at, and then check if this decimal is bigger than a certain decimal, like 0.9. fine tune this decimal, and you will see that the closer it is to 1, the closer you will need to spin the red part to the goal for it to satisfy the if condition! then you can put your function for what will happen once the red part is in the right spot, in that if statement.

local object = workspace.sanka2

local targetDirection = Vector3.new(0, -180, -180)

local dotProductThreshold = 0.99

local orientationCheckConnection = nil

local function checkOrientation()
local objectDirection = object.CFrame.LookVector
local dotProduct = objectDirection:Dot(targetDirection)

if dotProduct >= dotProductThreshold then
	object:Destroy()
	if orientationCheckConnection then
		orientationCheckConnection:Disconnect()  
	end
end

end

orientationCheckConnection = game:GetService(“RunService”).RenderStepped:Connect(function()
checkOrientation()
end)

Like this? Tell me if there is something wrong with it cause it didn’t work.