Help with CFrame script needed

Hello,
I need some help with a CFrame script.
I want to make the script rotate the part until is back at the default Orientation.
Issue: The script works but nothing happens once the orientation is default.

script.Parent.ClickDetector.MouseClick:Connect(function()
	script.Disabled = true
	repeat
			game.Workspace.Model.Main.Union.CFrame = game.Workspace.Model.Main.Union.CFrame * CFrame.fromEulerAnglesXYZ(0,0.1,0)
			wait(0.01)
	until game.Workspace.Model.Main.Union.CFrame == CFrame.fromEulerAngles(0,0,0)
	script.Disabled = false
end)

Thanks

1 Like

Why this… script.Disabled =

2 Likes

try this?

local A = game.TweenService


A:Create(script.Parent, TweenInfo.new(5), {Orientation = Vector3.new(360,0,0)}):Play()

plus, instead of disabling the script, do this:

Debounce = false
script.Parent.ClickDetector.MouseClick:Connect(function()
if not Debounce then
	Debounce = true
	repeat
			game.Workspace.Model.Main.Union.CFrame = game.Workspace.Model.Main.Union.CFrame * CFrame.fromEulerAnglesXYZ(0,0.1,0)
			wait(0.01)
	until game.Workspace.Model.Main.Union.Orientation == Vector3.new(0,0,0)
Debounce = false
end
end)

With the script i made, do this:

local A = game.TweenService

Debounce = false
script.Parent.ClickDetector.MouseClick:Connect(function()
if not Debounce then
	Debounce = true
local T = A:Create(game.Workspace.Model.Main.Union, TweenInfo.new(5), {Orientation = Vector3.new(0,360,0)}):Play()
T.Completed:Connect(function()
Debounce = false
    end)
end
end)

I need to make it with CFrame.

Can you explain why?

Text

Because CFrame will rotate the part quickly without slowness.

-- The following line does not work correctly.
until game.Workspace.Model.Main.Union.CFrame == CFrame.fromEulerAngles(0,0,0)

Not Exactly,

CFrame Contains 2 Properties that make it function:
Position
Orientation
When using one of them, you use Vector3

Well, and the TweenService will need to change the part’s position & orientation to a different, before playing.

TweenService asks you to set a Instance, and a Property to Change before Playing

_T:Create(_B.Base, -- My Part that i used
 TweenInfo.new(2), -- Tween Information, Only the Speed is there
 {Orientation = Vector3.new(0,360,0)} -- Sets Only the Orientation (Rotation)
):Play() -- Plays The Tween

If i wanted to, i can change the Position too,

_T:Create(_B.Base,
 TweenInfo.new(2),
 {Position = Vector3.new(0,0,0),Orientation = Vector3.new(0,360,0)}
):Play()

create a new cframe with a angle and position but in a variable.

local cf = CFrame.new(pos) * CFrame.Angles(math.rad(x), math.rad(y), math.rad(z))

local ts = game:GetService('TweenService')
local ti = -- your tween info
ts:Create(youritem, ti, {CFrame = cf}):Play()

since your trying to make it go back to default, set it to 0,0,0 or any value you want.

1 Like

It tried printing the info for the CFrame and it doesn’t seem to be possible with the CFrame.fromEulerAngles.

So maybe that is why it doesn’t stop playing. It can’t match what it can’t find.

Try printing:
print(game.Workspace.Model.Main.Union.CFrame)
vs.
print(game.Workspace.Model.Main.Union.CFrame.fromEulerAngles

1 Like

This line is the problem because it is looking for something it can’t find (I think).

until game.Workspace.Model.CFrame == CFrame.fromEulerAngles(0,0,0)

1 Like

The following line works also with fromOrientation.

game.Workspace.Model.Main.Union.CFrame = game.Workspace.Model.Main.Union.CFrame * CFrame.fromOrientation(0,0.1,0)