Issue with replacement script

Hello. I am having an issue with this script, where I am trying to replace every DoorScript, using the command bar, in the workspace with a new one. However, my stupid self made all the doors in different structures, so the only common item the doors have is the ‘ANOMALYDETECTOR’ part. So, I used that to find all scripts. However, this is not working.

The only door with the new script is SCAPEGOAT.

If something like this has been posted, please direct me towards it.
Thank you!


for i, v in pairs(game.Workspace:GetDescendants()) do
	if v:IsA("Part") and v.Name == "ANOMALYDETECTOR" then
		v.Parent.ProximityPrompt.Script:Destroy()
	local moom = game.Workspace.SCAPEGOAT.Model.Button.ProximityPrompt.DoorScript:Clone()
	moom.Parent = v.Parent.ProximityPrompt
	end
end

do all the ProximityPrompts have the same ActionText if so you can do something like this

for i, descendant in ipairs(game.Workspace:GetDescendants()) do
    -- if descendant is not a proximity prompt skip this descendant
    if descendant:IsA("ProximityPrompt") == false then continue end
    -- if the ActionText is not correct then skip this descendant
    if descendant.ActionText ~= "OPEN DOOR" then continue end
    -- destroy the old script
    descendant.Script:Destroy()
    -- clone the new script
    game.ReplicatedStorage.NewScript:Clone().Parent = descendant
end

but i would not recommend doing this as you will always run into the same problem every time you want to change the script instead what you should do is give all the doors a tag

https://developer.roblox.com/en-us/api-reference/class/CollectionService

then you can use one script to control all doors that have been tagged

here is a video that might help you tag all your doors

They do not, as there are two different kinds of doors.
Is there anything wrong with my script? Or am I not using command bar properly.
I’ll consider tagging later.

i don’t see anything wrong with your code

to use the command bar all you do is copy and paste the hole code into the command bar and press enter

also look at the output windows to see if there are any errors

if the script does not exist then this part might give a error

v.Parent.ProximityPrompt.Script:Destroy()

so you might want to use findfirstchild to get the script

Yes, that was the issue. Thank you.