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!
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.
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!
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.
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?
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