"The Parent property of Workspace is locked" error in the output

Hello,

The title is pretty self explanatory. I’m trying to move a part from ServerStorage to Workspace and get it to be destroyed once the script is done running. However with my attempted of doing so, I got the weird error:

image

The line it’s reffering to:
image

The script (nothing crazy):

local Model = script.Parent.Parent
local RustRemoverProp = game.Workspace.Givers.RustRemover
local GoofsNLaughsRoomDoor = game.Workspace.GoofsNLaughsRoomDoor.DoorFrame:WaitForChild("ProximityPrompt")
local RustyDoorHandle = script.Parent.Parent:WaitForChild("RustyDoorHandle")
local SizzlingSmoke = Model.Smoke.SmokeParticle
local SizzlingSound = Model.Smoke.Sizzling
local PouringLiquidSound = Model.RustyDoorHandleHitbox.PouringLiquid
local DoorNotBudgingGui = game.Workspace.DoorNotBudgingBrick
local StillDissolvingBrick = game.ServerStorage.StillDissolvingBrick

function ontouch(hit)
	local RustRemover = hit:findFirstChild("rustremoverkey")
	if RustRemover then hit.Parent:Destroy()
		RustRemoverProp:Destroy()
		DoorNotBudgingGui:Destroy()
		PouringLiquidSound:Play()
		PouringLiquidSound.Ended:Wait()
		SizzlingSmoke.Enabled = true
		SizzlingSound:Play()
		StillDissolvingBrick = workspace
		SizzlingSound.Ended:Wait()
		SizzlingSmoke.Enabled = false
		GoofsNLaughsRoomDoor.Enabled = true
		StillDissolvingBrick:Destroy()
		Model:Destroy()
		script:Destroy()
	end
end
script.Parent.Touched:Connect(ontouch)

What am I placing wrong? This should be a simple fix for someone experienced but since I’m still decent at scripting I wouldn’t know right away lol. I’d appreciate some help! :slight_smile:

You’re setting the variable StillDissolvingBrick to the actual workspace. I assume you possibly meant to set it to a parent of workspace instead (StillDissolvingBrick.Parent = workspace).

4 Likes

You get the error because once the part is destroyed, the parent is locked to nil and cannot be changed. With that being said, I see a couple of things wrong with your code.

  • I don’t see anywhere where you are cloning things to the workspace, you are using the objects from ServerStorage directly. So without cloning, once something gets :Destroy() called on it, the parent is locked to nil, but still exists until the garbage collector cleans it up. If you try to reuse the same object, you will get that error, even when destroying it again, because the underlying code is trying to set it to nil again but it’s locked.

  • The other thing is that you are destroying the script immediately. This is bad practice. You need to give it a few seconds to do any background cleanup that may be needed. Use the debris service like this:

local debrisService = game:GetService("Debris")

-- In your touched function
debrisService.AddItem(script, 5)

That will give it a few seconds for the underlying code to clean up before the script goes bye bye.

EDIT:

  • As others have mentioned, and I missed it, that one line of code StillDissolvingBrick = workspace probably should be StillDissolvingBrick.Parent = workspace instead.
local Model = script.Parent.Parent
local RustRemoverProp = game.Workspace.Givers.RustRemover
local GoofsNLaughsRoomDoor = game.Workspace.GoofsNLaughsRoomDoor.DoorFrame:WaitForChild("ProximityPrompt")
local RustyDoorHandle = script.Parent.Parent:WaitForChild("RustyDoorHandle")
local SizzlingSmoke = Model.Smoke.SmokeParticle
local SizzlingSound = Model.Smoke.Sizzling
local PouringLiquidSound = Model.RustyDoorHandleHitbox.PouringLiquid
local DoorNotBudgingGui = game.Workspace.DoorNotBudgingBrick
local StillDissolvingBrick = game.ServerStorage.StillDissolvingBrick

function ontouch(hit)
	local RustRemover = hit:findFirstChild("rustremoverkey")
	if RustRemover then hit.Parent:Destroy()
		RustRemoverProp:Destroy()
		DoorNotBudgingGui:Destroy()
		PouringLiquidSound:Play()
		PouringLiquidSound.Ended:Wait()
		SizzlingSmoke.Enabled = true
		SizzlingSound:Play()
		StillDissolvingBrick.Parent = workspace
		SizzlingSound.Ended:Wait()
		SizzlingSmoke.Enabled = false
		GoofsNLaughsRoomDoor.Enabled = true
		StillDissolvingBrick:Destroy()
		Model:Destroy()
		script:Destroy()
	end
end
script.Parent.Touched:Connect(ontouch)

here
I think you want to do this
image
right?

Good catch. I missed that. Looking at his code, he’s referencing objects in server storage directly. I don’t see where anything is being cloned. I think that could also be a problem too.

2 Likes

LOL, really did turn out all I had to do to fix this was simply add .Parent after StillDissolvingBrick in the StillDissolvingBrick = workspace line.

All I wanted to do was put StillDissolvingBrick inside game.Workspace and be able to destroy it after my script is done running.

Yeah I can see it not being the most effective method when destroying scripts but I’ve never really had a problem at all before, so it’s something I usually do.

Yup! Thank you all for your assistance :slight_smile: