Second Door Tween Fails To Work

My first click to open the door on this code works perfectly fine but on the second tween/click to close the door nothing happens. Any help with this script would be greatly appreciated.

local TweenService = game:GetService("TweenService")

local door = workspace.Door
local doorRoot = door.PrimaryPart -- important

local DoorSwingInfo = TweenInfo.new()

local DoorSwingTween = TweenService:Create(doorRoot, DoorSwingInfo, {
    CFrame = doorRoot.CFrame * CFrame.Angles(0, math.rad(-105), 0)
})

local DoorSwingCloseTween = TweenService:Create(doorRoot, DoorSwingInfo, {
    CFrame = doorRoot.CFrame * CFrame.Angles(0, math.rad(105), 0)
})

if script.Parent.IsOpen.Value == false then
script.Parent.ModernDoorHandleBack.ClickDetector.MouseClick:Connect(function()
    DoorSwingTween:Play()
    script.Parent.IsOpen.Value = true
end)
    
script.Parent.ModernDoorHandleFront.ClickDetector.MouseClick:Connect(function()
    DoorSwingTween:Play()
    script.Parent.IsOpen.Value = true
end)    
    
if script.Parent.IsOpen.Value == true then
script.Parent.ModernDoorHandleBack.ClickDetector.MouseClick:Connect(function()    
    DoorSwingCloseTween:Play()
    script.Parent.IsOpen.Value = false
end)
            
script.Parent.ModernDoorHandleFront.ClickDetector.MouseClick:Connect(function()
    DoorSwingCloseTween:Play()
    script.Parent.IsOpen.Value = true
end)
end
end

On the fourth function you whrote with mouse detector function on the ModernDoorHandleFront i think that the code bellow it with the
script.Parent.IsOpen.Value = true
should be
script.Parent.IsOpen.Value = false

Okay, I think I got how the script is meant to look.

local TweenService = game:GetService("TweenService")

local door = workspace.Door
local doorRoot = door.PrimaryPart -- important

local DoorSwingInfo = TweenInfo.new()

local DoorSwingTween = TweenService:Create(doorRoot, DoorSwingInfo, {
    CFrame = doorRoot.CFrame * CFrame.Angles(0, math.rad(-105), 0)
})

local DoorSwingCloseTween = TweenService:Create(doorRoot, DoorSwingInfo, {
    CFrame = doorRoot.CFrame * CFrame.Angles(0, math.rad(105), 0)
})

script.Parent.ModernDoorHandleBack.ClickDetector.MouseClick:Connect(function()
    if script.Parent.IsOpen.Value == false then
          DoorSwingTween:Play()
         script.Parent.IsOpen.Value = true
    elseif script.Parent.IsOpen.Value == true then  
        DoorSwingCloseTween:Play()
        script.Parent.IsOpen.Value = false
    end
end)
    
script.Parent.ModernDoorHandleFront.ClickDetector.MouseClick:Connect(function()
    if script.Parent.IsOpen.Value == false then
          DoorSwingTween:Play()
         script.Parent.IsOpen.Value = true
    elseif script.Parent.IsOpen.Value == true then  
        DoorSwingCloseTween:Play()
        script.Parent.IsOpen.Value = false
    end
end)

Let me know if it works, I didn’t test it before hand lol

This sort of works. Not sure how to fix it though.

robloxapp-20211016-1132486.wmv (1.0 MB)

Oops, don’t know how to embed…

Hmm, odd. I’ll see what I can do

All good lol, I just started replying to posts today so I don’t know how either

Try making the CFrame tween to:

CFrame = CFrame.new(doorRoot.CFrame.Position) * CFrame.Angles(0, math.rad(105), 0)

It may take some tweaking

Does the same as the video just sent. Hm.

Can I have the place file? Or just the door + script model?

I’ll send you a DM. thirtycharacterlimit

if it isn’t what I sent you then it should’ve been working before, maybe just too high of an increment?

I’m running out of ideas here, but you can try using a part to have so you can reset the door’s rotation and change it depending on that

To embed you need a recording software. Roblox only records in wmv which sucks for us cos it is terrible quality plus it doesn’t embed. Get obs and you can record much better quality.

If the door is already closed then you don’t need to transform / multiply the CFrame.

Small note: I would advise using a ProximityPrompt over ClickDetector it’s much more user friendly for computer and even modal devices too,

Hm, alright. I can try that. omgihatethischaracterlimit

What do you mean?

I’m using clickdetector as it kinda fits the game style more.

Well since the door in the video is closed already you don’t need to multiply.

local DoorSwingCloseTween = TweenService:Create(doorRoot, DoorSwingInfo, {
    CFrame = doorRoot.CFrame 
})

That works better that my idea, I forgot the value wasn’t being updated lol

Yeah I’m having it there so when it gets closed it goes to that. But any idea on how I could fix the door?

I sent the file, it should work
(Also, I messed with some random stuff so ignore how there isn’t any if statements)

1 Like