Need a help with this script. It is used to CFrame model without making gaps in it. But one weird thing is that it makes models to relocate and rotate in unnecessary directions. I made models stop relocating by inserting primary part position into CFrame.new line but there's still a problem with an unnecessary rotation. For example, firstly my model (primary part) orientation is 2,0,0, but when this script runs, orientation changes to 0,0,0. I have no idea what in the script makes model to do an unnecessary rotation as I need this model (primary part) to have orientation 2,0,0 instead of 0,0,0. In other words, I need my model to be tilted on 2 degrees when script runs, but that script always removes any tilt, making it 0. Here's the script I am working with:

    local cache = cache or {};
    local center = center or model.PrimaryPart.CFrame;
    for , child in next, model:GetChildren() do
        if (child:IsA("BasePart")) then
            cache[child] = center:inverse() * child.CFrame;
            --same thing as above: cache[child] = center:toObjectSpace(child.CFrame);
        end;
        cache = cacheOffset(child, cache, center);
    end;
    return cache
end
 
local function transformModel(model, cf, cache, center)
    local center = center or model.PrimaryPart.CFrame;
    for , child in next, model:GetChildren() do
        if (child:IsA("BasePart")) then
            child.CFrame = cf * cache[child];
            --same thing as above: child.CFrame = cf:toWorldSpace(cache[child]);
        end;
        transformModel(child, cf, cache, center);
    end;
end;
 
local Titanic = game.Workspace.RMSTitanic;
local cache = cacheOffset(Titanic);
local cf = CFrame.new(-84.43, -275.99, 564.598);
game:GetService("RunService").Heartbeat:connect(function(dt)
    cf = cf * CFrame.Angles(math.rad(0), math.rad(0), math.pi * 0);
    transformModel(Titanic, cf, cache);
end);```

1 comment

0

You put too many "`" to make it code. Use the Lua code option in the editor instead.