Motor6D, getting orientation somehow

I’m trying to work out the simplest method of determining the orientation of my part. It’s a spinning part similar to a roulette wheel that you spin and it slows down. I’ve got it all working except the sound plays each loop and doesn’t play with longer duration as the part slows down. I thought perhaps I could use the Motor6D itself and all I’d have to do is read when it reached 90 degrees and then play the sound. The sound is a short tic.


local base = script.Parent
local spinPart = script.Parent.Parent.SpinPart
local motor = script.Parent.Motor6D
local proxPrompt = script.Parent.Parent.ProximityPrompt
local depletionRate = 0.01
local sound = script.Parent.TicSound
sound.SoundId = "rbxassetid://9118137778"

local function spinParts(timer)
	proxPrompt.Enabled = false
	while true do
		if timer <= 0 then 
			proxPrompt.Enabled = true
			break 
		end
		timer = timer - depletionRate
		
		local newValue = timer
		print(newValue)
		
		motor.C0 = motor.C0 * CFrame.Angles(0, math.rad(newValue), 0)
		--I would like to use the orientation.Y somehow to play the sound

		if motor.C0.Rotation:ToOrientation(0,90,0) then --incorrect
			sound:Play()
		end
		
		task.wait(0.01)
	end
end

proxPrompt.Triggered:Connect(function()
	local maxTimer = math.random(1,3) * 10
	spinParts(maxTimer)
end)

1 Like

:ToOrientation returns radians, not degrees. And it will never be exaclty 90. You can do this

local _, rotY = motor.C0.Rotation:ToOrientation()
if math.round(math.deg(rotY)) == 90 then
	-- do something
end

Should I run it in it’s own thread and I’ve observed that perhaps it will never be 90 by the time the loop get s to it.