Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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

Log in to vote
1
Answered by
Vulkarin 581 Moderation Voter
6 years ago

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
Ad
Log in to vote
0
Answered by 6 years ago

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

Answer this question