Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

if i try to change a welds orientation it destroys it self how can i fix this?

Asked by
hokyboy 270 Moderation Voter
3 years ago

if I try to change the orientation of the part it either does not work or the weld destroys itself is there a fix for this?

I heard u can use weld constraints I tried but I did not understand

-- grimoire code

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EventFolder = ReplicatedStorage:WaitForChild("EVENTS")
local Remote = EventFolder.ActivateGrimoire

function GetGrimoire(player)
    local Char = player.Character
    local Hurmp = Char.HumanoidRootPart
    local DataFolder = player.Data
    local Grimoire = DataFolder.Grimoire
    local GrimoireName = Grimoire.Value

    if GrimoireName == "None" then
        warn("Player Does Not Have Grimoire")
    else
        warn(GrimoireName)
        local GrimoireFolder = script:WaitForChild(GrimoireName):Clone()
        local NewGrimoire = GrimoireFolder.Open
        NewGrimoire.Parent = workspace
        NewGrimoire.Orientation = Vector3.new(0,0,24)

        wait(.01)

        local NewWeld = Instance.new("Weld")
        NewWeld.Parent = Hurmp
        NewWeld.Part0 = Hurmp
        NewWeld.Part1 = NewGrimoire
        NewWeld.C0 = CFrame.new(0, -.5, -3)

    end
end

EventFolder.ActivateGrimoire.OnServerEvent:Connect(function(Player)
    GetGrimoire(Player)
end)

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Sorry I don't know anything about this but maybe looking through this source code from a plugin can help( i didn't make this):

local plugin = PluginManager():CreatePlugin()
local button = plugin:CreateToolbar("GeomTools"):CreateButton("Transform","Freezes attachments for transformations","rbxassetid://606821411")
local mouse = plugin:GetMouse()

---------------[[ Main ]]---------------

local function partMoved(p)
    -- arbitrary wait fixes everything
    wait()
    local part = p.Part
    local originCFrame = p.OriginCFrame
    local originSize = p.OriginSize
    local newCFrame = part.CFrame
    for _, a in pairs(p.Attachments) do
        local attachment = a.Attachment
        local attachmentOriginCFrame = CFrame.new(a.OriginalPosition) * CFrame.Angles(math.rad(a.OriginalRotation.X), math.rad(a.OriginalRotation.Y), math.rad(a.OriginalRotation.Z))

        local correctedCFrame = newCFrame:toObjectSpace(originCFrame) * attachmentOriginCFrame
        attachment.Position = correctedCFrame.p
        local x, y, z = correctedCFrame:toEulerAnglesXYZ()
        attachment.Rotation = Vector3.new(math.deg(x), math.deg(y), math.deg(z))
    end
end


---------------[[ Collect Parts ]]---------------

local parts = {}

local function tableContains(list, instance)
    for _, v in pairs(list) do
        if v == instance then
            return true
        end
    end
    return false
end

local function getAttachments(part)
    local attachments = {}
    for _, v in pairs(part:GetChildren()) do
        if v:IsA("Attachment") then
            table.insert(attachments, {Attachment = v, OriginalPosition = v.Position, OriginalRotation = v.Rotation})
        end
    end
    return attachments
end

local function getParts(instanceList, partList, gottenParts)
    partList = partList or {}
    gottenParts = gottenParts or {}
    for _, v in pairs(instanceList) do
        if v:IsA("BasePart") and not tableContains(gottenParts, v) then
            table.insert(gottenParts, v)
            local part = {Part = v, OriginCFrame = v.CFrame, OriginSize = v.Size, Attachments = getAttachments(v)}
            if #part.Attachments > 0 then
                part.UpdateConnection = v.Changed:connect(function() partMoved(part) end)
                table.insert(partList, part)
            end
        end
        getParts(v:GetChildren(), partList, gottenParts)
    end
    return partList
end

local function disconnectUpdates()
    for _, part in pairs(parts) do
        part.UpdateConnection:disconnect()
    end
    parts = {}
end
---------------[[ Inputs ]]---------------

local function updateSelection()
    if active then
        disconnectUpdates()
        parts = getParts(game.Selection:Get())
    end
end
game.Selection.SelectionChanged:connect(updateSelection)


mouse.KeyDown:connect(function(key) --27 escape, 13 enter
    if not active then
        return
    end

    key = string.byte(string.lower(key))
    if key == 27 then
        active = false
        button:SetActive(false)
    end
end)

plugin.Deactivation:connect(function()
--  active = false
--  button:SetActive(false)
end)

button.Click:connect(function()
    active = not active
    local active2 = active
    plugin:Activate(active)
    active = active2
    button:SetActive(active)
    if active then
        updateSelection()
        warn("Freeze attachments plugin active. Transforming and resizing parts will not affect the absolute positions of their attachments.")      
    else
        disconnectUpdates()
        warn("Freeze attachments plugin disabled.")
    end
end)
Ad

Answer this question