How to scale and move model depending on parent object

  1. What do you want to achieve? | I want to be able to move and scale models depending on where/the scale of the parent object is, like how houses and other building scales and moves with plates in a game like Plates of Fate

Example:

  1. What is the issue? | I can’t seem to find a good way to achieve this goal.

  2. What solutions have you tried so far? | I’ve tried to seek help on youtube and developing discord servers, but none have been helpful

You could detect when the plate’s size has changed and divide it by the plate’s original size to find the scaling factor.

local plate = workspace.Plate -- part
local house = workspace.House -- model
local originalSize = plate.Size.X

plate:GetPropertyChangedSignal("Size"):Connect(function()
     house.Scale = plate.Size.X / originalSize
end)
-- Function to scale and move a model
function scaleAndMoveModel(model, scaleFactor, newPosition)
    -- Scale the model
    for _, part in ipairs(model:GetDescendants()) do
        if part:IsA("BasePart") then
            part.Size = part.Size * scaleFactor
            local relativePosition = part.Position - model.PrimaryPart.Position
            part.Position = newPosition + relativePosition * scaleFactor
        end
    end

    -- Move the model
    local primaryPartCFrame = model.PrimaryPart.CFrame
    model:SetPrimaryPartCFrame(CFrame.new(newPosition) * (primaryPartCFrame - primaryPartCFrame.p))
end

-- Example usage
local model = script.Parent -- The model you want to scale and move
local scaleFactor = Vector3.new(2, 2, 2) -- The scale factor (2x size in this example)
local newPosition = Vector3.new(0, 50, 0) -- The new position to move the model to

scaleAndMoveModel(model, scaleFactor, newPosition)

your model should have a PrimaryPart set, which is used as a reference point for scaling and moving. The scaleAndMoveModel function takes three arguments: the model to be scaled and moved, the scale factor as a Vector3 , and the new position as a Vector3 .

Is there also a way where you can scale an object to the plate’s size when it’s not at it’s original size? Sometimes the plate will already be bigger and the building will spawn at it’s original size.

Example:


The plate is already big and the house spawned at it’s original size. Is there anyway I can make it spawn big along with the plate?

Is there also a way where you can scale an object to the plate’s size when it’s not at it’s original size? Sometimes the plate will already be bigger and the building will spawn at it’s original size.

Example:

The plate is already big and the house spawned at it’s original size. Is there anyway I can make it spawn big along with the plate?

Nevermind. Found it out, thanks to everyone who helped!

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