Rotation doesn't tween

So I have like mini door of a postal box that is supposed to rotate when a proximity prompt is triggered.

local main = script.Parent.Parent

local prompt = script.Parent

local TweenService = game:GetService("TweenService")
local SoundService = game:GetService("SoundService")
local Sound = SoundService.PostalSounds.Sound
local sound_length = 0.85
local tweening_info = TweenInfo.new(0.8, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)

local info_1 = {CFrame = main.CFrame * CFrame.Angles(0, math.rad(135), 0)}
local info_2 = {CFrame = main.CFrame * CFrame.Angles(0, math.rad(45), 0)}

local tween_1 = TweenService:Create(main, tweening_info, info_1)
local tween_2 = TweenService:Create(main, tweening_info, info_2)

prompt.Triggered:Connect(function(player)
	if main.Orientation == Vector3.new(0, 45, 0) then
		prompt.Enabled = false
		tween_1:Play()
		Sound:Play()
		task.wait(sound_length)
		Sound:Pause()
		prompt.Enabled = true
	elseif main.Orientation == Vector3.new(0, 135, 0) then
		prompt.Enabled = false
		tween_2:Play()
		Sound:Resume()
		prompt.Enabled = true
	end
end)

I am using this script to rotate the part. I know for sure that it passed the if stament because the sound is playing, it is paused right at time but the tween is nowhere to be working.

Screenshot (15)

I have also done a weld script to glue everything. I have provided this photo if this may be the cause of the problem. But what is causing the problem after all?

1 Like

It could be that you’re trying to tween anchored parts.
Make sure the parts being welded onto the main part are unanchored, and the main part can be anchored.

Besides that, you might want to create a boolean to record whether the door is open or not. That way you aren’t looking for the orientation of the door and instead know if it’s open or closed.

IsDoorOpen = false
prompt.Triggered:Connect(function(player)
	if IsDoorOpen then
		-- Close door.
	else
		-- Open door.
	end
	IsDoorOpen = not IsDoorOpen
end)

Also, it could be useful going forward to use that logic in case you decide to rotate the postal box later in development. (Where X and Z may not always be 0 on those axis.)

Try simplifying, so you can isolate and test the tween.

IsDoorOpen = false
prompt.Triggered:Connect(function(player)
	if IsDoorOpen then

		-- Close door.

		local goal = {}
		goal.CFrame = main.CFrame * CFrame.Angles(0, math.rad(135), 0)
		local tweenInfo = TweenInfo.new(0.8, Enum.EasingStyle.Linear)
		local tween = TweenService:Create(part, tweenInfo, goal)
		tween:Play()

	else

		-- Open door.

		local goal = {}
		goal.CFrame = main.CFrame * CFrame.Angles(0, math.rad(45), 0)
		local tweenInfo = TweenInfo.new(0.8, Enum.EasingStyle.Linear)
		local tween = TweenService:Create(part, tweenInfo, goal)
		tween:Play()

	end
	IsDoorOpen = not IsDoorOpen
end)

Try to make it work, then make it efficient later.

For some reason it still doesn’t work.

robloxapp-20240131-2053526.wmv (1.2 MB)

I want to mention that the only anchored parts in the whole model are the mesh parts. The other parts is the door itself and the it’s doorknob, parts which don’t need to get anchored. Even with the configurations set and the code copiedexactly it doesn’t rotate when triggered for some reason.

Anchored parts can most certainly be tweened.

Anchored parts can be tweened.

Then what is actually causing the problem?

Is the prompt actually trigging? Can you check by using a print statement after it is triggered?

Yes, it does actually trigger. I even put a sound in there and it was doing the job but Tween wasn’t.

So that means it is trigging and meeting the checks. Thats a good sign so far. Now its just time to find out whats wrong.

You cannot change the orientation of a welded part. If you physically look at the orientation through properties, it is changing, but it doesn’t show since it’s locked to another parts orientation, to fix this, either tween the C0 of the weld, or the primary part of the weld.

1 Like

Can you tell more spefically how to actually do this because when I try to do such thing it doesn’t consider the pivot point and when I try to rotate it while welded it simply falls off:

robloxapp-20240201-1616149.wmv (1.9 MB)

You can see in the video where the part changes orintation, like it kind of went to the right of the postal box. That’s when I changed the C1 orientation. Which absolutely didn’t care about the pivot.

local main = script.Parent.Parent
local prompt = script.Parent
local TweenService = game:GetService("TweenService")
local SoundService = game:GetService("SoundService")
local Sound = SoundService.PostalSounds.Sound
local sound_length = 0.85
local tweening_info = TweenInfo.new(0.8, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)

local initialCFrame = main.CFrame
local info_1 = {CFrame = initialCFrame * CFrame.Angles(0, math.rad(135), 0)}
local info_2 = {CFrame = initialCFrame * CFrame.Angles(0, math.rad(45), 0)}

local tween_1 = TweenService:Create(main, tweening_info, info_1)
local tween_2 = TweenService:Create(main, tweening_info, info_2)

prompt.Triggered:Connect(function(player)
    if (main.CFrame:toEulerAnglesXYZ()) == (initialCFrame * CFrame.Angles(0, math.rad(45), 0):toEulerAnglesXYZ()) then
        prompt.Enabled = false
        tween_1:Play()
        Sound:Play()
        task.wait(sound_length)
        Sound:Pause()
        prompt.Enabled = true
    elseif (main.CFrame:toEulerAnglesXYZ()) == (initialCFrame * CFrame.Angles(0, math.rad(135), 0):toEulerAnglesXYZ()) then
        prompt.Enabled = false
        tween_2:Play()
        Sound:Resume()
        prompt.Enabled = true
    end
end)

1 Like

Didn’t work and I got this error :frowning: :

Workspace.Postal.Secondary.ProximityPrompt.Script:17: invalid argument #2 (Vector3 expected, got number)

Alright figured it out, I deleted every single weld constraint in the model, with a little exception. Next, I anchor every part except the door handle, which I welded to the door, shouldn’t affect enything. Using the hint that anchored parts can be tweened that you guys said, I implemented the script and saw that it’s working at last.

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