The Parent property of ___ is locked, current parent: NULL,

hello devs i currently have this problem in my scsript when i set the clone parent to workspace it only happens when the script is run for the second time tho

--[SETUP]
--get services
local runservice = game:GetService("RunService")
local uis = game:GetService("UserInputService")
local rs = game:GetService("RunService")
--finds player stuff
local plr = game.Players.LocalPlayer

local myPlayer = game.Players.LocalPlayer
local myChar = myPlayer.Character
local myHum = myChar:WaitForChild("Humanoid")
local myHRP = myChar:WaitForChild("HumanoidRootPart")
local camera = game.Workspace.CurrentCamera

local atch =  Instance.new("Attachment")
local parti1 = game.ReplicatedStorage.ParticleEmitter:Clone()
local parti2 = game.ReplicatedStorage.ParticleEmitter:Clone()
-- bool
local flying = false
local deboince = false
left = myHRP.Position + Vector3.new(0, 30, 0) * 150

local plr = game.Players.LocalPlayer
local bv = Instance.new("BodyVelocity")

local cam = game.Workspace.CurrentCamera
local bodyForce = Instance.new("BodyForce")

local explo = game.ReplicatedStorage.Meteor:Clone()

local bp = Instance.new("BodyPosition", myHRP)
bp.MaxForce = Vector3.new()
bp.D = 10
bp.P = 10000

local bg = Instance.new("BodyGyro", myHRP)
bg.MaxTorque = Vector3.new()
bg.D = 10
spaces = 0

atch.Parent = myHRP
parti1.Parent = atch
parti2.Parent = myChar.Head
parti1.Rate = 0
parti2.Rate = 0

myChar.Humanoid:GetPropertyChangedSignal("Jump"):Connect(function()
	if deboince == false  then
		deboince = true
		spaces = spaces + 1
		if spaces == 2 then
			if flying == false then
				flying = true
				--[for parti1cle emmiter]
				--[When the player starts to fly then]--
				parti2.Rate = 300
				parti1.Rate = 300
				print(os.time()) 
				explo.Parent = game.Workspace--error here
				explo.Position = myHRP.Position
				os.difftime(1, 1.5)
				bodyForce.Parent = myHRP
				cam.FieldOfView += 10
				bodyForce.Force = bodyForce.Parent.CFrame:vectorToWorldSpace(left)
				wait(.2)
				cam.FieldOfView -= 10
				wait(.5)
				bodyForce:Destroy()
				wait(.1)
				explo:Destroy()
				--finds player info
				bv.Parent = myHRP
				bv.MaxForce = Vector3.new(99999, 99999, 99999)
				bv.Velocity = Vector3.new(0, 0, 0)
				--[adds parti1cle emmiter]--
				spaces = 0
			elseif flying == true then
				flying = false
				parti1.Rate = 0
				parti2.Rate = 0
				myHRP.BodyVelocity:Destroy()
				--endFlying()
				spaces = 0
			end
		else
			wait(2)
			spaces = 0-- if they dont press space again in the next 1 second
		end
	end
	wait(.5)
	deboince = false
end)


--[if player dies]--
local function death()
	flying = false
end
myChar.Humanoid.Died:Connect(death)

--[setup DO NOT FIDDLE]--
--player stuff

local debounce = false

--define body velocity
--for explosion


local function onPartTouched(otherPart)
	if debounce == false then
		debounce = true
		-- Get the other part's parent
		local partParent = otherPart.Parent
		-- Look for a humanoid in the parent
		local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
		if humanoid then
			if flying then
				myHum.Health = myHum.Health - 10
				flying = false
				myHRP.Attachment.ParticleEmitter:Destroy()
				myChar.Head.ParticleEmitter:Destroy()
				myHRP.BodyVelocity:Destroy()
				wait(1)
			end
		end
		debounce = false
	end
end
myHum.Touched:Connect(onPartTouched)
--[Execution]--
runservice.RenderStepped:Connect(function(step)
	if flying == true then
	--[onhit]
		local Velocity = myChar.Humanoid.MoveDirection* Vector3.new(50, 0, 50) + game.Workspace.CurrentCamera.CoordinateFrame.lookVector * Vector3.new(0, 50, 0)
		bv.Velocity = Velocity
	end
end)

error --The Parent property of Meteor is locked, current parent: NULL, new parent Workspace

13 Likes

Then you:

However explo isn’t recloned again while the script runs multiple times, so after explo:Destroy() reclone it.

				explo:Destroy()
explo = game.ReplicatedStorage.Meteor:Clone()--get a new explo in the variable

12 Likes

it solves the error but now it will be cloned again

1 Like

Calling Destroy will lock the parent property as per usual. Every time you discard the old part, overwrite the variable with a new copy of the previous. The original instance should be appropriately stored.

3 Likes