Hello!
I’m trying to make a door system using TweenService. It’s supposed to close when a player touches a button and to open when the player touches again the button.
It closes and opens well, but it stops working when I try to close it for second time.
I tried to do loops and returns, but nothing worked.
local MPS = game:GetService("MarketplaceService")
local passId = 9917540
local TweenService = game:GetService("TweenService")
local ClickMe = game.Workspace.ClickMeGamePass.ClickDetector
local Door = game.Workspace.SecurityDoor
local openPosition = game.Workspace.OpenedDoor
local closedDooor = game.Workspace.ClosedDoor
function onMouseClick()
local Info = TweenInfo.new(
2,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
local Goals = {
Position = Vector3.new(-1.44, 4.5, -1.485)
}
local OpenGoals = {
Position = Vector3.new(-1.44, 13.5, -1.485)
}
if Door.Position == openPosition.Position then
local closeDoorTween = TweenService:Create(Door, Info, Goals)
closeDoorTween:Play()
else
local openDoorTween = TweenService:Create(Door, Info, OpenGoals)
openDoorTween:Play()
end
end
game.Players.PlayerAdded:Connect(function(Player)
if MPS:UserOwnsGamePassAsync(Player.UserId, passId) then
end
end)
ClickMe.MouseClick:Connect(onMouseClick)