CFrame:GetComponents() Only Returns 1 Number

I’m trying to store a player’s furniture data, and I keep having this problem of the furniture’s position only loading 1 dimension out of the 3 its supposed to have. I looked more into this issue and found that the method i used to store the object’s cframe into the datastore was acting strange.

heres my issue:
when the player leaves the game, i run through every piece of furniture in the player’s house, and store its position relative to the player’s home (an object value stored in the player thats set to the home model whenever the player purchases a home/loads their data into an empty home) using this function:

if player.home.Value ~= nil then
			local props = {}
			
			for i,v in ipairs(player.home.Value.furniture:GetChildren()) do
				if v:IsA("Model") then
					local cf = player.home.Value:GetPivot():ToObjectSpace(v:GetPivot())
					
					local furnituredata = {
						itemtype = v:GetAttribute("itemtype"),
						cframecomponents = cf:GetComponents()
					}
					
                    -- this is where my issue is, it only returns 1 number
					print(furnituredata.cframecomponents)
					table.insert(props, furnituredata)
				end
			end
			
			local propdatasave = httpserv:JSONEncode(props)
			
			propstore:SetAsync(player.UserId, propdatasave)
		end

when i get the cframe value, i run GetComponents() on the cframe so i can place it in a datastore thats json encoded with httpservice. this is where i noticed the issue, i ran a print statement on the cframe thats being stored, and it only returns 1 number of the 12 cframe values that a cframe typically has.

That function returns a Tuple, and only one key is being assigned (the first returned value). Wrap that function in a table and you can access via numerical index.

1 Like

Not sure what you mean by wrapping, this is the first time ive ever used GetComponents() for anything, so im not very familiar with what it does. can you pls explain more

Tulple means multiple values are being returned. In this case, 12 numbers are being returned.

local x, y, z = someCFrame:GetComponents()

-- you will only be able to use the first 3 returned values of this function

By wrapping it in a table, you store all returned values in a table that you can access via components[index].

1 Like

thanks for the help, i’ve been stuck on this for while

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