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

7 comments
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...
...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.
maybe check to see if the motor6ds are being cloned
My solution might just be to model it in blender and just use that
yea maybe
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!
can you post a link of your game so i can play it?