Parenting causing instance to be destroyed

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    i want my props to be able to be parented to another part without getting destroyed

  2. What is the issue? Include screenshots / videos if possible!
    i have 2 scripts that place props, they use the exact same code but only one works. after alot of debugging i found out that parenting to the part makes it so that it gets destroyed but the other script does that without getting destroyed

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    i have tried everything on devforum and i even turned locked on but it still got destroyed

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

-- This is an example Lua code block
local function placeProp(Part:BasePart,prop,offset:number,rotate : boolean,seed)
    task.wait()
    local RandomService = Random.new(seed)
    local propMultiplier = RandomService.NextNumber(RandomService,0.8,1.2)
    local adjustedHeight = 1
    local newProp = prop:Clone()
    if newProp:IsA("BasePart") then
        adjustedHeight = (Part.Size.Y / 2)+ ((prop.Size.Y * propMultiplier) / 2)
        local x = Part.Position.X + RandomService.NextInteger(RandomService,-(Part.Size.X / 1.25)/2,(Part.Size.X / 1.25)/2)
        local z = Part.Position.Z + RandomService.NextInteger(RandomService,-(Part.Size.Z / 1.25)/2,(Part.Size.Z / 1.25)/2)
        local adjustedPosition = Vector3.new(x,((Part.Position.Y + adjustedHeight)- offset),z)        
        local orient = newProp.Orientation
        if rotate == true then
            orient = Vector3.new(newProp.Orientation.X,RandomService.NextInteger(RandomService,0,360),newProp.Orientation.Z)
        end
        newProp.Orientation = orient
        newProp.Size *= propMultiplier
        newProp.Position = adjustedPosition
        newProp.Parent = Part
    elseif newProp:IsA("Model") then
        local x = Part.Position.X + RandomService.NextInteger(RandomService,-(Part.Size.X / 1.25)/2,(Part.Size.X / 1.25)/2)
        local z = Part.Position.Z + RandomService.NextInteger(RandomService,-(Part.Size.Z / 1.25)/2,(Part.Size.Z / 1.25)/2)
        adjustedHeight = (Part.Size.Y / 2)+ ((prop.PrimaryPart.Size.Y * propMultiplier) / 2)
        local adjustedPosition = Vector3.new(x,((Part.Position.Y + adjustedHeight)- offset),z)        
        local xr,yr,zr = newProp:GetPivot():ToOrientation()
        if rotate == true then
            xr,yr,zr = newProp:GetPivot():ToOrientation().X,RandomService.NextInteger(RandomService,0,360),newProp:GetPivot():ToOrientation().Z
        end
        newProp:PivotTo(CFrame.new(adjustedPosition) * CFrame.Angles(xr,yr,zr))
        for i,v in pairs(newProp:GetChildren()) do
            if v:IsA("BasePart") then
                v.Size *= propMultiplier
            end
        end
        newProp.Parent = Part
    end  
end
1 Like

Did you check if the adjustedPosition is not below the workspace’s destroy line? It’s possible that when the newProp is set to that position, it gets destroyed before even parenting to the part.

1 Like

i did, it was above the line and in the correct spot

The Locked property only affects whether or not the object can be selected while editing.

In the case that each script happens to be cloning different props, check the Anchored and CanCollide properties of the BasePart(s) within the original props that are being sent to the function. If both are false, then the “newProp” is likely falling into the void after being cloned and parented to the Part in the Workspace.

1 Like

i saw that on another post. i have anchored on and cancollide off

1 Like

my friend cant comment but here is what he was gonna say:

i found a script that randomly deleted descendant right as it was created. i put a if statement so that nothing gonna get deleted

1 Like

also thank you guys you made me start checking the scripts and find the problem

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.