Need help getting the part position and the part size

So basically im trying to get the part position and then get the part position later in the script…

No idea what im doing but here is the code:

local garageDoor = script.Parent
local clickDetector = script.Parent.ClickDetector
local DEBOUNCE = false
local OPEN = false
local amount = 1
local doorOpenSound = script.Parent.DoorOpen
local doorClosedSound = script.Parent.DoorClose

--getting the open position
local openSize = game.Workspace.SmallHouse.GarageDoorModel.PositionOpen.Size
local openPosition = game.Workspace.SmallHouse.GarageDoorModel.PositionOpen.Position
--getting the closed position
local closeSize = game.Workspace.SmallHouse.GarageDoorModel.PositionClosed.Size
local closePosition = game.Workspace.SmallHouse.GarageDoorModel.PositionClosed.Position

clickDetector.MouseClick:Connect(function()
	if not DEBOUNCE then
		DEBOUNCE = true

		if not OPEN then
			OPEN = true
			doorOpenSound:Play()
			--putting the open position in the vector3 (Doesnt do anything)
			garageDoor.Size = Vector3.new(openSize)
			garageDoor.Position = Vector3.new(openPosition)
		else
			OPEN = false
			doorClosedSound:Play()
			--putting the closed position in the vector3 (Doesnt do anything)
			garageDoor.Size = Vector3.new(closeSize)
			garageDoor.Position = Vector3.new(closePosition)
		end
		
		task.wait(amount)
		DEBOUNCE = false
	end
end)

You are creating a new Vector3, which is not needed.

		if not OPEN then
			OPEN = true
			doorOpenSound:Play()
			--putting the open position in the vector3 (Doesnt do anything)

			-- You don't need to create a new Vector3, because
			-- when you store the size and position in the variables,
			-- the values are already Vector3
			garageDoor.Size = openSize
			garageDoor.Position = openPosition
		else
			OPEN = false
			doorClosedSound:Play()
			--putting the closed position in the vector3 (Doesnt do anything)
			garageDoor.Size = closeSize
			garageDoor.Position = closePosition
		end

Hope this helps!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.