Same Script used over again?

I am currently trying to make a script that when touched by player disappears then comes back after a while, I have the code all in and it works, now I am currently trying to duplicate the part.

The problem is that when I duplicate the part the script doesn’t save through, and personally I would it so its only one script changing all the parts when touched by a player.

I have tried duplicating the part that doesn’t save the script though, I looked up a solution and I came across someone who had a similar problem, the answer was to use a plugin with tags, but I would rather not use a plugin if possible

I would personally do something along the lines of putting all of the parts you want this script to run on in a folder/model and then writing one script that runs code for all of them. For example, lets say its a folder in workspace named “TouchParts”. We can write code for this:

for _, part in pairs(workspace.TouchParts:GetChildren()) do
    part.Touched:Connect(function()
          --Code for that
    end)
end

Hope this helps! :slight_smile:

1 Like

Ok thank you i will try this, and I would put this script in serverscriptservice?

1 Like

Sure! You can put it in ServerScriptService or workspace. I would definitely prefer ServerScriptService though.

So it works, But I have a debounce in my script and it makes it not able to do more than one at a time when I take it out it works but because the debounce is gone it makes it seem a little bit glitchy

1 Like

Ok! You can have a debounce inside of each part then.

for _, part in pairs(workspace.TouchParts:GetChildren()) do
   local debounce = false
    part.Touched:Connect(function()
          if not debounce then
               debounce = true
               --Code for that

               wait(whatever time it is)
               debounce = false
          end
    end)
end

Oh wait! I just realized you could make a new variable inside of the for loop instead of having to make a BoolValue. My mistake!

Ok thank you ill try, also on your post up top you said “(post withdrawn by author, will be automatically deleted in 1 hour unless flagged)” what does that mean?

Oh I was writing a post and accidentally didn’t finish it before sending. Don’t worry about it. :slight_smile:

oh ok, thank you for all your help

No problem. Tell me if it works out. It should I’m pretty sure :slight_smile:

yep it worked thank you, what should I mark as the solution?

Whichever one you want to choose :slight_smile:

ok ill probably choose the first answer it seems more relevant to the topic name