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()
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