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?
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