I need help with tables

I have created 4 separate tables to hold the values for open and close on my tweenservice door and i’m wondering
if theirs a way for me to do this in only 1 table.

local bottomOpen = {}
bottomOpen.CFrame = bottomDoor.CFrame + Vector3.new(0,-2,0)

local bottomClosed = {}
bottomClosed.CFrame = bottomDoor.CFrame
		
local topOpen = {}
topOpen.CFrame = topDoor.CFrame + Vector3.new(0,5,0)

local topClosed = {}
topClosed.CFrame = topDoor.CFrame 

1 Like

You can use a dictionary to hold all of the CFrames.

local doorCFrames = {
	bottomOpen = bottomDoor.CFrame + Vector3.new(0,-2,0),
	bottomClosed = bottomDoor.CFrame,
	
	topOpen = topDoor.CFrame + Vector3.new(0,5,0),
	topClosed = topDoor.CFrame
}

print(doorCFrames.bottomOpen)
1 Like

Adding to @instabologna123’s solution,

In your code with 4 tables, each table is a dictionary with only 1 value, where the key name is “CFrame”, and the value is the CFrame
You could get rid of every table and replace it with a simple variable, as only 1 value is stored in each table, or as Jonah suggested, you can give a unique name to each CFrame to be able to store all of them in a single table. You’ll then have to use a pairs() loop onto that table if you want to avoid manually indexing every value. (or no iterator, as that is now possible)

1 Like

Yeah i tried it that way i’m assuming, it is saying Unable to cast to Dictionary because i dont have a loop

Its getting stuck here

doors.ClickDetector.MouseClick:Connect(function()
	if Activated == false then
		local openBottom = tweenService:Create(bottomDoor,tweenInfo,doorCFrames.bottomOpen)

This is returning

{
CFrame = CFrame.new(....)
}

You can not input a table into the tween, and you are inputting a table. You need to input the CFrame.

local openBottom = tweenService:Create(bottomDoor,tweenInfo,doorCFrames.bottomOpen.CFrame)
1 Like

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