I found this door opening script on youtube that causes the door to move upwards when a button is clicked, but I don’t understand a line. Here’s the full script:
local TweenService = game:GetService("TweenService")
local door = script.Parent.Parent.Door
local doorButton = script.Parent
local clickDetector = script.Parent.ClickDetector
local doorClosed = true
local doorClosedPosition = door.Position
local doorClosedSize = door.Size
clickDetector.MouseClick:Connect(function()
local doorTweenInfo = TweenInfo.new(2)
local endPosition = {}
if doorClosed == true then
endPosition.Position = Vector3.new(door.Position.X, door.Position.Y + door.Size.Y/2, door.Position.Z)
endPosition.Size = Vector3.new(door.Size.X, 0, door.Size.Z)
doorButton.BrickColor = BrickColor.new("Really red")
doorClosed = false
else
endPosition.Position = doorClosedPosition
endPosition.Size = doorClosedSize
doorButton.BrickColor = BrickColor.new("Lime green")
doorClosed = true
end
local tween = TweenService:Create(door, doorTweenInfo, endPosition)
tween:Play()
end)
I realised the door just slides upwards and through the frame as opposed to shrinking to oblivion. To be honest I still don’t 100% understand the code of adding the size to position then dividing by 2, then have 0 in the next line when defining the size for y. I get it is so that the door goes back uptop instead of the middle but how does it do that, as in why adding the size divided by 2 will cause it to do that? Also by writing “door.Position.x”, does it mean the X coordinate remains unchanged?