Sliding door script not working

Hello. For my game I am creating a sliding door script, but for some reason door 1 doesn’t open and door 2 just spams close and open even though there is a wait. Any help will be appreciated, here is the script.

local TweenService = game:GetService(“TweenService”)

local door1 = script.Parent:WaitForChild(“Door1”)

local door2 = script.Parent:WaitForChild(“Door2”)

local tweeningInformation = TweenInfo.new(

0.5,

Enum.EasingStyle.Linear,

Enum.EasingDirection.Out,

0,

false,

0

)

local door1Open = {CFrame = CFrame.new(-53.727, 9.115, 155)}

local door2Open = {CFrame = CFrame.new(-78.244, 9.035, 154.98)}

local door1Close = {CFrame = CFrame.new(-61.607, 9.115, 155)}

local door2Close = {CFrame = CFrame.new(-70.43, 9.035, 154.98)}

local tween1open = TweenService:Create(door1, tweeningInformation, door1Open)

local tween1close = TweenService:Create(door1, tweeningInformation, door1Close)

local tween2open = TweenService:Create(door2, tweeningInformation, door2Open)

local tween2close = TweenService:Create(door2, tweeningInformation, door2Close)

script.Parent.Detector2.Touched:Connect(function(hit)

tween1open:Play()

tween2open:Play()

wait(2)

tween1close:Play()

tween2close:Play()

end)

script.Parent.Detector1.Touched:Connect(function(hit)

tween1open:Play()

tween2open:Play()

wait(2)

tween1close:Play()

tween2close:Play()

end)

4 Likes

Did you set the positions of the door correctly? And also do you get any errors in the output?

3 Likes

no errors and pos is correct so idk

2 Likes

Hmm so I know that you used AlvinBlox’s tutorial. From his pastebin script, this is what the script is supposed to look like besides the positions. It looks like you have everything correct though. Try going through this script if you find any mistakes.

AlvinBlox Door Code:

local TweenService = game:GetService("TweenService")
local door1 = script.Parent:WaitForChild("Door1")
local door2 = script.Parent:WaitForChild("Door2")
local tweeningInformation = TweenInfo.new(
    0.5,    
    Enum.EasingStyle.Linear,
    Enum.EasingDirection.Out,
    0,
    false,
    0
)
local door1Open = {CFrame = CFrame.new(-4.23, 3.99, -8.56)}
local door2Open = {CFrame = CFrame.new(-26.57, 3.99, -8.56)}
local door1Close = {CFrame = CFrame.new(-11.57, 3.99, -8.56)}
local door2Close = {CFrame = CFrame.new(-18.91, 3.99, -8.56)}
local tween1open = TweenService:Create(door1,tweeningInformation,door1Open)
local tween1close = TweenService:Create(door1,tweeningInformation,door1Close)
local tween2open = TweenService:Create(door2,tweeningInformation,door2Open)
local tween2close = TweenService:Create(door2,tweeningInformation,door2Close)
 
script.Parent.Detector1.Touched:Connect(function(hit)
    tween1open:Play()
    tween2open:Play()
    wait(2)
    tween1close:Play()
    tween2close:Play()
end)
script.Parent.Detector2.Touched:Connect(function(hit)
    tween1open:Play()
    tween2open:Play()
    wait(2)
    tween1close:Play()
    tween2close:Play()
end)
1 Like

use a debounce

a debounce is something like

local p = false
function main()
 if p == false then
 p = true
  wait(2)
 p = false
end -- you cannot use this function until the wait is over
main()
1 Like