Changing cframe depending on house position

In short, I have a furniture system where the cframe of the object in the house is saved, however I want it to be able to change depending on which house it’s in, since I dont want furniture spawning in another random player’s house. Right now, I have

furniture_object:SetPrimaryPartCFrame(savedCFrame)

and obviously that wouldn’t work if they had a different house than the starting one, so how would I change it so that it accounts for the new house’s position?

I tried searching here for similar issues, but didn’t find anything

thanks in advance!

an offset position variable, you could save how far away the furniture is from the middle of the house

Detail: Having a Invisible Centre Part In The House and saving the distance from the part to where it is placed

1 Like

Whilst you’re saving the CFrame of the object, be sure to make it relative via finding the inverse of the house’s base. Egomoose did this rather well in his placement system.

--Example Code (for saving the position)
local position = plrHouse.Base.CFrame:inverse() * Object:GetPrimaryPartCFrame()
--Example Code (for loading)
local components = {}

for num in string.gmatch(cf, "[^%s,]+") do
	components[#components+1] = tonumber(num)
end

Object:SetPrimaryPartCFrame(plrHouse.Base.CFrame * CFrame.new(unpack(coms)))
1 Like

I attempted this, and…


How do I make it account for height ?

local HouseCenterPart = House.Center
local FurnitureObject = Object

-- Saving The Position
local SavedPosition = HouseCeterPart.Position - FurnitureObject.Position

-- Loading The Position
FurnitureObject.Position = HouseCenterPart.Position + SavedPosition

2 Likes