While cloning The Parent property of __________ is locked, current parent: NULL, new parent Workspace

While cloning an item it says The Parent property of ________ is locked, current parent: NULL, new parent Workspace.

Is there anyway to fix this?

The bosses attack script :

local v1 = game.ReplicatedStorage["Gaster tester1"]:Clone()
local humroot = script.Parent.HumanoidRootPart
while true do
	wait(1)
	v1.Parent = workspace
	v1:SetPrimaryPartCFrame(humroot.CFrame)
	v1:TranslateBy(Vector3.new(5, 5, 5))
end

The Model I’m cloning script :

local blaster = nil
local re = nil
task.wait(3)
re = script.Parent.Parent:Clone()
re.Parent = game.ReplicatedStorage
blaster = script.Parent.Parent
blaster:Destroy()

Help of course would be greatly appreciated thank you!

It might be that you tried cloning and reparenting a destroyed object.

5 Likes

I am not sure whether this will work but go to the parent of the model and check in the Properties tab whether the .Locked property is set to true; if it is then set it to false.

https://developer.roblox.com/en-us/api-reference/property/BasePart/Locked

Edit:

In the bosses attack script change the first line to:

local v1 = game:GetService('ReplicatedStorage'):WaitForChild('Gaster tester1')
local v1clone = v1:Clone()
1 Like

Yeah I’ve tried tons of things and cloned it multiple times and tried to reclone it and parent it back but nothing works.

I’ll see thanks, When I look on the model there seems to be no .Locked

Can you answer some of these questions:

What are you trying to clone?
Why are you destroying it?
Why do you want to clone it?

An attack from my boss a blaster, which shoots a beam and I dont want it to stay there forever so I delete it.

I want to destroy it since if it stays it will become basically impossible for the player to defeat the boss.

I want to clone it since I can make multiple that appear at the same time and not just in the same area.

From what I can see in your code and your problem I am going to assume you are cloning a bunch of blasters that will parent itself to the boss and will shoot a beam out and then you are immediately deleting the blaster - correct me if I am wrong.

A better approach to your problem:

I understand your problem to the extent that you do not want to leave the blaster with the boss because it will keep firing beams/bullets towards the player; however, there are multiple ways in which you can solve this instead of assuming the beam is still there and causing your script to yield.

The best way I can think of is using a cooldown to ensure bullets/beams do not come out of the blaster immediately after one another so you can prevent making the boss impossible for the player to defeat e.g:

local cooldown, WAIT = false, 3

if not cooldown then
    cooldown = true
    
    beam:Clone()
    fireBeam(beam)
    
    task.wait(WAIT)
    beam:Destroy()
    cooldown = false
end

If you want to be even more specific I would suggest a counter to check how many bullets you want to fire and if it exceeds the limit do not fire anymore bullets and delete the blaster itself e.g:

local MAX_BULLET_LIMIT = 5 -- would fire 5 bullets only

for 1, MAX_BULLET_LIMIT do
  local beam = beam:Clone()
  fireBullet(beam)
  task.wait(3)
  beam:Destroy()
end
blaster:Destroy()

These are the two best ways I can think of going about your problem or if you would like a hacky solution you could check if the beam exists using

 if ReplicatedStorage:FindFirstChild('beam') then -- checks if beam exists
-- execute function
else
  return 
end

I hope this gives you an idea about what you may want to do, good luck!

2 Likes

If you wait before trying to access something, even if it is to call :Destroy() the object, you’ll want to make sure it isn’t already destroyed or you will get the error that you are seeing.

I’d suggest, after every wait() to also check
if object and object.Parent then
before doing anything with the object.

1 Like

I’m confused, How come theres a function fireBeam there, Is there anyway to sync :Clone() to a function?

local v1 = game:GetService('ServerStorage'):WaitForChild('Gaster Test')
local v1clone = v1
local humroot = script.Parent.HumanoidRootPart
function Detect(fireBeam)
task.wait(3)
v1clone:Clone()
v1clone.Parent = workspace
v1clone:SetPrimaryPartCFrame(humroot.CFrame)
v1clone:TranslateBy(Vector3.new(5, 5, 5))

end

local cooldown, WAIT = false, 3

if not cooldown then
	cooldown = true

	v1clone:Clone()
	fireBeam(v1clone)

	task.wait(WAIT)
	v1clone:Destroy()
	cooldown = false
end

I’m trying something like this but it doesn’t work?

1 Like

Let us go back to your original script but let’s make a few changes:

local blaster = nil
local re = nil
task.wait(3)
re = script.Parent.Parent:Clone()
re.Parent = game.ReplicatedStorage
blaster = script.Parent.Parent

if blaster then blaster:Destroy() else print('Object was already destroyed') end

By adding this line of code:
if blaster then blaster:Destroy() else print('Object was already destroyed') end

you are checking whether the object was already destroyed and if it wasnt then you destroy it - let me know if this works

1 Like