This is a door script I found on Youtube that allows the door the move upwards when a button is pushed.
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)
What does “Door.Position.x/y/z” mean and do? Why do I have to do “door.Position.Y + door.Size.Y/2”? Well I get it’s so that door goes uptop instead of the middle but how does adding the size divided by 2 cause it to do that?
The position of the door is always in the middle of it. So in order to position it on top of the ground, I have to make the door be half of it’s own size higher. I’ll draw a picture in case my wording is kind of hard to understand