Can't Properly place a script insided tagged Items

Hi! :3
I have an empty script (that will fill later) inside Replicated Storage.
I also have the parts that will contain the Script inside Rep. Storage.

With the following code I’m trying to add the script to each of the parts that have a “Lights1” or “Lights2” tag.

--Variables
tagService = game:GetService("CollectionService")
replicatedScripts = game.ReplicatedStorage.DecorScripts

taggedPartsLightPrimary= tagService:GetTagged("Lights2")
taggedPartsLightSecondary = tagService:GetTagged("Lights1")

--Adds Primary Lights Music script to tagged Parts
for index, part in ipairs(taggedPartsLightPrimary) do
	local clonedScript = replicatedScripts.LightMusicPrimary:Clone()
	clonedScript.Parent = part
	
end

--Adds Secondary Lights Music script to tagged Parts
for index, part in ipairs(taggedPartsLightSecondary) do
	local clonedScript = replicatedScripts.LightMusicSecondary:Clone()
	clonedScript.Parent = part
end

Are the parts will belong to local player once cloned. So, with everything set, Both scripts clone, but in the wrong place.

They should clone inside each “Lights1 / Lights 2” of each “Building”. But are getting clonned directly as you can see inside “Buildings” group.

Any help would be appreciated :smiley:

If I ever add credits to the game or something, will include your support :3

1 Like

Are you sure that you have the correct objects tagged?

Try putting a print(part) inside of one of the for loops, to make sure it prints your desired parts.

Also, if it is just those parts you are working with, it would much be easier to remove CollectionService from the process. You could reference the parts directly from workspace.

Buildings = workspace.PlayerSideDoor.Decor.City.Buildings:GetChildren()
for _, object in pairs(Buildings) do
if object.Name == "Building" then
local clonedScript = replicatedScripts.LightMusicSecondary:Clone()
clonedScript.Parent = object.Lights1
local clonedScript = replicatedScripts.LightMusicSecondary:Clone()
clonedScript.Parent = object.Lights2
end
end
2 Likes

Thanks! :smiley:
What I was getting was this:

Captura

My mistake… I added both tags also to the “Buildings” group, now everything seems fixed :3

Captura2

Thanks so much! :smiley: If I ever add credits would you mind if your username appears in those?
It was a simple advice, but I wouldn’t have guessed :stuck_out_tongue:

If you’re interested this is the game, it’s private now, unless you want to add me as a friend.

Btw, I won’t remove Collection Service because in the future the script will also work with other parts at different time :3

1 Like

No need to give me any sort of credit. I’m happy to help!

I would love to check out your game though. Could you DM me the details, and we could talk about it?

Yup! :smiley: very glad you’re interested.