Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I am trying to make a rotating door but the close tween is not working. Can anybody help?

Asked by 4 years ago

The code below I have tried in multiple different ways, but anyway I am attempting to open a door that is tweened and it should be working. The open tween works just fine and sets the value to open, but when I close it, it sets the open value to false, like it should, but the tween doesn't do anything, I looked at the playback state and it said it was playing when I fired it, but it isn't closing. This is all done on a localscript. There are other scripts involved that send a message to this localscript, but they work fine.

local TweenService = game:GetService("TweenService")
wait(.2)
game:GetService("ReplicatedStorage").DoorEvent.OnClientEvent:Connect(function(Door)
    local Open = Door:FindFirstChild("Scripted").Open
    local Debounce = Door:FindFirstChild("Scripted").Debounce

    local DoorRoot = Door.Scripted:WaitForChild("RootHinge")

    local DoorSwingInfo = TweenInfo.new() -- Let's use all defaults here

    local PanelSwingOpenTween = TweenService:Create(DoorRoot, DoorSwingInfo, {
        CFrame = DoorRoot.CFrame * CFrame.Angles(0, math.rad(93), 0)
    })

    local PanelSwingCloseTween = TweenService:Create(DoorRoot, DoorSwingInfo, {
        CFrame = DoorRoot.CFrame * CFrame.Angles(0, 0, 0)
    })

    if Debounce.Value == false then
        Debounce.Value = true
        if Open.Value == false then
            print("opening")
            PanelSwingOpenTween:Play()
            Open.Value = true
        elseif Open.Value == true then
            Open.Value = false
            PanelSwingCloseTween:Play()
        else
            print("if this actually happened then roblox has absolutely broken")
        end
        wait(3)
        Debounce.Value = false
    end
end)

If there is any important information I've left out, just comment and I'll try my best to add it when I get back online.

2 answers

Log in to vote
0
Answered by 4 years ago

Funny enough. This is exactly the type of project I was working on. The issue is with the way you've setup your CFrame. I'm a bit foggy on the actual specifics but essentially when you multiply a CFrame by a CFrame.Angles , then it will "add" the values to the part's current CFrame rather than setting it which it looks like you're trying to do. So just change line 16 to:

CFrame = DoorRoot.CFrame * CFrame.Angles(0, math.rad(-93), 0)

Also, for any more knowledgeable scripters, please feel free to explain the actual formula that's going on with CFrames being multiplied as I'm sure mine isn't the best explanation.

Ad
Log in to vote
0
Answered by
sleazel 1287 Moderation Voter
4 years ago

The real issue here is that you are creating new tweens every time there is an event. Tween are based on the door current CFrame, so it will get messed up if the event fires when door are not in the starting position. To fix, you will need to remember door starting CFrame.

local TweenService = game:GetService("TweenService")
wait(.2)
    })

local Doors = {} --table to remeber all doors CFrames, assuming there are more than one

game:GetService("ReplicatedStorage").DoorEvent.OnClientEvent:Connect(function(Door)


    local Open = Door:FindFirstChild("Scripted").Open
    local Debounce = Door:FindFirstChild("Scripted").Debounce

    local DoorRoot = Door.Scripted:WaitForChild("RootHinge")

    local DoorSwingInfo = TweenInfo.new() -- Let's use all defaults here

   --check if its first time doors are being referenced, if so remember CFrame
   if not Doors[Door] then
      Doors[Door] = DoorRoot.CFrame
   end

    local PanelSwingOpenTween = TweenService:Create(DoorRoot, DoorSwingInfo, {
        CFrame = Doors[Door] * CFrame.Angles(0, math.rad(93), 0)
    })

    local PanelSwingCloseTween = TweenService:Create(DoorRoot, DoorSwingInfo, {
        --CFrame = DoorRoot.CFrame * CFrame.Angles(0, 0, 0)
        CFrame = Doors[Door] --for close tween you just have to use starting position, assuming doors are closed at the start of the game

    if Debounce.Value == false then
        Debounce.Value = true
        if Open.Value == false then
            print("opening")
            PanelSwingOpenTween:Play()
            Open.Value = true
        elseif Open.Value == true then
            Open.Value = false
            PanelSwingCloseTween:Play()
        else
            print("if this actually happened then roblox has absolutely broken")
        end
        wait(3)
        Debounce.Value = false
    end
end)

Hope that helps.

0
He's already got a debounce variable in place so there should never point where you can reactivate the door before it's done tweening. XxTrueDemonxX 362 — 4y
0
What i meant was that it will fail when event fires when door are open, since close tween is based on the current door position and wont do anything. sleazel 1287 — 4y

Answer this question