I’m creating a game in it when one part touches another it changes the parent and that part does the same to others. but I have been having some issues with it I have been getting this error The Parent property of Part is locked, current parent: NULL, new parent Junk - Server - JunkConfig:11
Heres the script `function touched(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
hit.Parent:FindFirstChild(“Humanoid”).Health = 0
elseif hit.Name == “Baseplate” then
else
hit.Material = Enum.Material.CorrodedMetal
hit.Anchored = false
wait(1)
if hit.Parent == game.Workspace or hit.Parent == game.Workspace:FindFirstChild("Map1") or hit.Parent == game.Workspace:FindFirstChild("Map2") or hit.Parent == game.Workspace:FindFirstChild("Map3") or hit.Parent == game.Workspace:FindFirstChild("Map4") then
hit.Parent = game.Workspace:WaitForChild("Junk")
end
end
end
local PartFolder = game.Workspace:WaitForChild(“Junk”)
–add parts with similar properties in the same folder
–or use CollectionService to organize them together
–looping through the entire game isn’t efficient!
local parts = PartFolder:GetChildren()
PartFolder.ChildAdded:Connect(function(child)
if not child then
print(“Bruh”)
else
Right I think some could be possibly. I’ll check that tomorrow. But even after all the parts that would have a touched event fire for them are destroyed it starts outputting the error is there any way there could be latency or something in the script?
function touched(hit)
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent:FindFirstChild("Humanoid").Health = 0
elseif hit.Name == "Baseplate" then
else
hit.Material = Enum.Material.CorrodedMetal
hit.Anchored = false
task.wait(1)
if string.match(hit.Parent.Name, "^Map[0-9]+$") then
hit.Parent = workspace:WaitForChild("Junk")
end
end
end
local PartFolder = game.Workspace:WaitForChild("Junk")
local parts = PartFolder:GetChildren()
PartFolder.ChildAdded:Connect(function(child)
child.Touched:Connect(touched)
end)
function touched(hit)
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent:FindFirstChild("Humanoid").Health = 0
elseif hit.Name == "Baseplate" then
else
hit.Material = Enum.Material.CorrodedMetal
hit.Anchored = false
task.wait(1)
if hit.Parent then
if string.match(hit.Parent.Name, "^Map[0-9]+$") then
hit.Parent = workspace:WaitForChild("Junk")
end
end
end
end
local PartFolder = game.Workspace:WaitForChild("Junk")
local parts = PartFolder:GetChildren()
PartFolder.ChildAdded:Connect(function(child)
child.Touched:Connect(touched)
end)