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

Why does the sound play but the tween not?

Asked by 4 years ago

When the DoorHandle is clicked, a sound should play and the door should open. After 5 seconds, another sound plays and the door closes.

But, when I click the DoorHandle, only the sound plays but the tween does not, therefore not opening the door.

There were no errors on the output, there are two DoorHandles on each side of the door, with the same children and same scripts, I also checked on the Developer Forum but they didn't know what was the problem.

local tweenService = game:GetService("TweenService")
local doorFrame = script.Parent.Parent.DoorFrame
local phantomDoorFrame1 = script.Parent.Parent.PhantomDoorFrame1
local phantomDoorFrame2 = script.Parent.Parent.PhantomDoorFrame2
local clickDetector = script.Parent.ClickDetector

local tweeningInformation1 = TweenInfo.new(
    0.834, -- Duration
    Enum.EasingStyle.Back, -- Easing style
    Enum.EasingDirection.Out, -- Easing Direction
    0, -- Number of repetitions
    false, -- Reverse boolean
    0 -- Delay time between each repetition
)

local partProperties1 = {
    CFrame = phantomDoorFrame1.CFrame
}

local partProperties2 = {
    CFrame = phantomDoorFrame2.CFrame
}

local tween1 = tweenService:Create(doorFrame, tweeningInformation1, partProperties1)
local tween2 = tweenService:Create(doorFrame, tweeningInformation1, partProperties2)

function openDoor()
    local doorOpenSound = script.Parent.Parent.DoorFrame.DoorOpen
    local doorCloseSound = script.Parent.Parent.DoorFrame.DoorClose
    local debounce = false
    if debounce == false then
        doorOpenSound:Play()
        tween1:Play()
        debounce = true
        wait(5)
        debounce = false
        if debounce == false then
            doorCloseSound:Play()
            tween2:Play()
        end
    end
end

clickDetector.MouseClick:Connect(openDoor)

I also used print() to look for a faulty line of code, here it is

if debounce == false then
            doorCloseSound:Play()
            tween2:Play()
        end
0
CFrame is a keyword. You shouldn't be using it as a variable name in lines 17 and 21 Gey4Jesus69 2705 — 4y
0
Also, in your `openDoor` function, you're setting debounce to false and then asking if debounce is false, so it's always false. Then, at line 37, you do the exact same thing. Stop using if statements if there's no need for them Gey4Jesus69 2705 — 4y
0
CFrame can be used like this on arrays, like a dictionary. You can call it like this then partProperties["CFrame"], but the tween function already uses it properly, as long as you dont add a property the tweened object doesn't have or a property that isnt tweenable (Name,Text,BrickColor) Dfzoz 489 — 4y
0
Seems to work for me. Here is the gif https://gyazo.com/2470f030f945b5873321d6ee838dea38. Only problem is the debounce there, clicking multiple times is playing the sound a lot of times.. Dfzoz 489 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Nevermind, I'll just use another method.

Ad

Answer this question