Cloning in Command bar not working properly

So, I’m trying to clone a script, and parent it to proximityPrompts. Well, it ain’t working, but the way I typed the code was the same way I did many other times and it worked, cloning to all the parts indentified with the given info, and without any errors.

I tried to delete and type it again and again but no success. And also I didn’t find any articles who could answer it properly.

Maybe this is a silly issue with me, or maybe how the script is typed, but I would like to understading what’s happening, cuz it may be useful in the future.

This is two different lines of codes that I’ve written in command bar:

-- local newscript = game.ServerStorage.OilCansSS:FindFirstChild("SSFinder") for _,v in ipairs(game.ServerStorage.OilCansSS:GetDescendants()) do if v:IsA("ProximityPrompt") then newscript:Clone() newscript.Parent = v end end
--  local newscript = game.ServerStorage.OilCansSS:FindFirstChild("SSFinder"):Clone() for _,v in ipairs(game.ServerStorage.OilCansSS:GetDescendants()) do if v:IsA("ProximityPrompt") then newscript.Parent = v end end

SSFinder is the script that I want to clone, and the P.P.s are inside the parts/meshes/unions
image

Tested it and the SSFinder is being cloned, but only parented to one part
image

1 Like
newscript:Clone()
newscript.Parent = v

You’re cloning newscript, but you’re not creating a variable for the cloned instance. When you use :Clone() on an instance, its parent is automatically set to nil, so what’s happening is that these instances are being discarded, and all you’re doing is moving the original script around.

I assume that’s the issue, because I don’t know how to replicate the second screenshot with the code you provided

Instead, you have to do this:

local cloned = newscript:Clone()
cloned.Parent = v

Or, if you don’t want the variable, you can do this as well:

newscript:Clone().Parent = v

Thanks for the clarification mate! It perfectly worked

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.