Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does the sound play but the tween not?

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

4 comments

0

CFrame is a keyword. You shouldn't be using it as a variable name in lines 17 and 21

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

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)

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

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.