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

How do I insert objects/scripts into multiple parents at once?

I'm trying to figure out how I can insert a script into multiple objects at one time using code, here's what I'm trying to use:

parts = game.Workspace.LargeBoat.Parts:GetChildren()

for i = 1,#parts do
	hscript = game.ServerScriptService.HealthScript:Clone()
	hscript.Parent = game.Workspace.LargeBoat.Parts:FindFirstChild("Part")
end

It's not working, would it only be putting one script into one part?

2 answers

✓ Accepted answer

I'm going to take a solid swing that it's going to be putting all of the scripts into the exact same part, all you need to do is change line 5

parts = game.Workspace.LargeBoat.Parts:GetChildren()

for i = 1,#parts do
    hscript = game.ServerScriptService.HealthScript:Clone()
    hscript.Parent = parts[i]
end

Maybe try using this.

local hscript = game:GetService("ServerScriptService").HealthScript
local parts = workspace.LargeBoat.Parts:GetChildren()

for i,v in pairs(parts) do
	hscript:Clone()
	hscript.Parent = v
end

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