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

[Solved] Parts not staying together when cloning?

Asked by 4 years ago
Edited 4 years ago

So I've been trying to make a box that opens when you press e while hovering over it, I've got all of it done except for one thing. When I press e it runs this code:

print("Open")
local OG = target.UnboxedItem.Value
local CO = OG:Clone()
CO.Parent = target.Parent
CO.Position = target.Position
target:Destroy()

here is the part I'm trying to clone: https://imgur.com/hSctTei Every time it clones the main part separates from the rest of the parts. If I put the part in the workspace and play the game they stick together so Idk what's happening.

Any help would be appreciated - kikuhou

Edit: here the function that code above is a part of

function Context(actionName, UserInputState,InputObject)
    --check
    if actionName == "Move" then
        local target = player:GetMouse().Target
        if target then
            local PickUpText = target:FindFirstChild("CanGrab")
            if Dragger == nil then
                if PickUpText then
                    local Owner = target:FindFirstChild("Owner")
                    if Owner.Value ~= "F" then
                        if target.Boxed.Value == true then
                            ContextText.Text = PickUpText.Value
                            ContextGui.Enabled = true
                            ELabel.Visible = true
                            MouseLabel.Visible = false
                            mouse.KeyDown:connect(function(key)
                                if key == "e" then
                                    print("Open")
                                    local OG = target.UnboxedItem.Value
                                    local CO = OG:Clone()
                                    CO.Parent = target.Parent
                                    CO.Position = target.Position
                                    target:Destroy()
                                end
                            end)
                        elseif Owner.Value ~= player.Name then
                            ContextText.Text = Owner.Value
                            ContextGui.Enabled = true
                            ELabel.Visible = false
                            MouseLabel.Visible = true
                        else
                            ContextText.Text = PickUpText.Value
                            ContextGui.Enabled = true
                            ELabel.Visible = false
                            MouseLabel.Visible = true
                        end
                    elseif Owner.Value == "F" then
                        ContextText.Text = "Unowned"
                        ContextGui.Enabled = true
                        ELabel.Visible = false
                        MouseLabel.Visible = true
                    end
                else
                    ContextGui.Enabled = false
                    ELabel.Visible = false
                    MouseLabel.Visible = false
                end
            end
        end
    end

    --print("UserInputState: " .. UserInputState.Value)
    --print("InputObject: " .. InputObject.UserInputType.Value)
end

Edit 2: I did it! I changed the code from:

print("Open")
local OG = target.UnboxedItem.Value
local CO = OG:Clone()
CO.Parent = target.Parent
CO.Position = target.Position
target:Destroy()

to:

print("Open")
local OG = target.UnboxedItem.Value
local CO = OG:Clone()
local CH = CO:GetChildren()
CO.Parent = target.Parent
CO.Position = target.Position
for i = 1, #CH do
    if CH[i].Name == "Peice" then
        local CC = CH[i]
        CC.Position = CC.Position + CO.Position
    end
end
target:Destroy()

1 answer

Log in to vote
0
Answered by
NSMascot 113
4 years ago

When you clone the box, I'm not sure if you are cloning the welds, therefore it may of broke. Also don't use target as it does not work with what you are trying to do: https://developer.roblox.com/en-us/api-reference/property/Mouse/Target

maybe try

local OG = workspace.BetaScrapper

BTW, I can't really help you that much becuase there is not much information to work from, maybe add a link to a video of the error! Here Is some links that may help you: https://developer.roblox.com/en-us/api-reference/function/Instance/Clone , https://developer.roblox.com/en-us/api-reference/function/Instance/GetDescendants , https://developer.roblox.com/en-us/api-reference/function/Instance/FindFirstAncestor , I Hope this helps a bit, NSMascot

1
So im sorry I didnt put the whole function in so I just edited it, the point of what I was trying to do was when your hovering over the box and press e it will destroy the box and clone in a part form replicated storage. That works when its a single part and not what should be a mesh. Now I have a lot of parts inside a part and when Im not cloning it, it works perfectly. Its just that the other... kikuhou 6 — 4y
0
...parts aren't going to the main part and if I try to change there position to the same as the main part (which is invisible btw, it's acting like a hitbox) they all go inside each other and don't look right, plus they still don't stay with the main invisible one. kikuhou 6 — 4y
0
maybe check to see if the motor6ds are being cloned NSMascot 113 — 4y
0
My solution might just be to model it in blender and just use that kikuhou 6 — 4y
View all comments (3 more)
0
yea maybe NSMascot 113 — 4y
0
I did it, all I had to do was find all the parts of the actual model then add their current position to the copies position. (Their current position was like 0,0,0 so yeah) It worked perfectly thanks! kikuhou 6 — 4y
0
can you post a link of your game so i can play it? NSMascot 113 — 4y
Ad

Answer this question