A way to Fire a Script once per Server? - Solution: CollectionService

Title.
Effectively I have a lot of Parts (with the same name) that I want to clone a script to, but I have found a bug in the code, and would have to edit one script then go through (at the moment) 40 parts and paste the script into it.

I was thinking that if I fired this script on the Server, the scripts would all be there when the first player joins.

Is this possible or would I have to do it with a Local Script for every user when the join, which could cause other issues.

Your question had too little detail, next time include more detail. It’s best that you explain things thoroughly because if it’s not appealing or it’s not described well, people will shift away and stop helping you. Sorry, if I sound rude, I just wanted to give some feedback.


It seems like you had a problem that I’ve had when I was just starting to develop. I had so many identical scripts, that when I had to edit one, I had to edit all of them. Fortunately, though, I have found a great Youtube tutorial about CollectionService. Basically what it does is you tag items with the Tag Editor and then loop through the items with a for loop:

local CS = game:GetService("CollectionService")
local Parts = CS:GetTagged("Parts") 
--[[ 
    You would add a tag named "Parts" and then tag all the instances
    (in this case, the parts that are causing your problem) then you
    would loop through all the instances that you've tagged. If you
    don't understand, go watch the youtube video in this post.
--]]

for i, Part in pairs(Parts) do
    -- Code here
end
1 Like

This is exactly what I needed.