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.
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?
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.
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.
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.
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:
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.
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.