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

How can I fix this script so a door would open/close when I click on it?

Asked by 4 years ago

Ok, I was writing a Tween script where when you click on the door, it opens or closes depending on it's status. But the script is broken and I don't know what the problem is.

Here's the code:

local opener =  script.Parent
local tween = game:GetService("TweenService")
local opened = false
local pos = CFrame.new(30.75, 3, 141.375)
local rot = CFrame.Angles(0, math.rad(120), 0)

local tweenInfo =  TweenInfo.new(
    1,
    Enum.EasingStyle.Linear,
    Enum.EasingDirection.Out,
    1,
    false,
    0
)

local goals = {
    opener.CFrame == pos * rot
}

local tweenData = tween:Create(opener, tween, goals)

local function onMouseClick()
    if opened == false then
        opened = true
        tweenData:Play()
    else
        opened = false
        pos = CFrame.new(28.75, 3, 139.875)
        rot = CFrame.Angles(0, math.rad(0), 0)
        tweenData:Play()
    end
end

opener.ClickDetector.MouseClick:Connect(onMouseClick)

1 answer

Log in to vote
0
Answered by 4 years ago

Hi! This Is How To Do It For No Collide Door:

script.Parent.MouseButton1Click:Connect(function()
script.Parent.CanCollode = False
wait(5) -- Change The Time To How Long It Stays Open
script.Parent.CanCollide = true
end)

Working On The Opening One

Ad

Answer this question