Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

how can i check if there's already a copy of this script in the workspace?

i'm making a script that people can put in models they can insert, but since there might be more than two inserted models with the same script (and i want this script to be placed in workspace instead of the model that it came with, just for ease of use and convenience), but if i just parent it to workspace, there will be two of them, and i can't delete the one that already exists because that would break the whole system, i'm currently using this set of lines of code (code block below), but it doesn't seem to be working as i'd want it to (it just doesn't parent itself to workspace at all regardless if there's already another one in there)

can anyone help me with this?, if you can, i'd be very thankful

(NameOfScript is the name of the script for testing)

b = workspace:FindFirstChild("NameOfScript")
if b ~= nil then 
	script.Parent = workspace
end
--(rest of the script is below)

2 comments

0

what is this script parented to before being parented to workspace?

0

it is parented to the model that was inserted

1 answer

Try this:

if workspace:FindFirstChild("XXX") then
	script.Parent = workspace
end
-- ...

2 comments

0

didn't work

0

Is the script you're looking for directly under workspace? Or is it parented to something else?

This discussion is preserved as it was. New answers, comments, and votes are closed.