I have this script that is supposed to create a model, clone 2 items and parent them to the model, create an instance and pivot it to its previous parent. TL;DR, script is supposed to clone into all 3 models, but doesn’t clone into the last model, only creates the instance.
Here is the code (The second for i, v loop is to check if there is any models that doesn’t have enough children(it also doesn’t work)
local AllMonitors = game.Workspace.GeneratedConcreteTunnels:WaitForChild("Connector").MonitorFolder
local PropMonitors = AllMonitors.PropMonitors
local PositionMonitors = AllMonitors.PositionMonitors
local WorkingMonitors = AllMonitors.WorkingMonitors
local ServerMonitorTemplate = script.ExampleMonitor
local ServerScreen = script.Screen
local ServerViewPart = script.ViewPart
for i, v in pairs(PositionMonitors:GetChildren()) do
local MonitorTemplate = ServerMonitorTemplate:Clone()
local Screen = ServerScreen:Clone()
local ViewPart = ServerViewPart:Clone()
local monitorParent = Instance.new("Model")
MonitorTemplate.Parent = monitorParent
Screen.Parent = MonitorTemplate
ViewPart.Parent = monitorParent
monitorParent.Parent = WorkingMonitors
local weldconstraint = Instance.new("WeldConstraint")
local weldconstraint2 = Instance.new("WeldConstraint")
weldconstraint.Part0 = MonitorTemplate
weldconstraint.Part1 = Screen
weldconstraint2.Part0 = MonitorTemplate
weldconstraint2.Part1 = ViewPart
monitorParent:PivotTo(CFrame.Angles(0,0,0))
monitorParent:PivotTo(v.CFrame)
ViewPart:PivotTo(ViewPart.CFrame*CFrame.new(0,0,3))
local MonitorValue = Instance.new("NumberValue")
MonitorValue.Name = "MonitorOrder"
MonitorValue.Parent = monitorParent
monitorParent.Name = "Monitor"..v.MonitorOrder.Value
MonitorValue.Value = v.MonitorOrder.Value
local MonitorUI = script.MonitorUIFolder.UI:Clone()
MonitorUI.Parent = MonitorTemplate
MonitorUI.Adornee = MonitorTemplate.Screen
local MonitorPrompt = script.MonitorUIFolder.MonitorProxTemplate:Clone()
local MonitorPromptValue = MonitorValue:Clone()
MonitorPromptValue.Parent = MonitorPrompt
MonitorPrompt.Parent = MonitorTemplate
MonitorPrompt.Adornee = MonitorTemplate
end
for i, v in pairs(WorkingMonitors:GetChildren()) do
if #v:GetChildren() < 2 then
local MonitorTemplate = ServerMonitorTemplate:Clone()
local Screen = ServerScreen:Clone()
local ViewPart = ServerViewPart:Clone()
local monitorParent = Instance.new("Model")
MonitorTemplate.Parent = monitorParent
Screen.Parent = MonitorTemplate
ViewPart.Parent = monitorParent
monitorParent.Parent = WorkingMonitors
local weldconstraint = Instance.new("WeldConstraint")
local weldconstraint2 = Instance.new("WeldConstraint")
weldconstraint.Part0 = MonitorTemplate
weldconstraint.Part1 = Screen
weldconstraint2.Part0 = MonitorTemplate
weldconstraint2.Part1 = ViewPart
monitorParent:PivotTo(CFrame.Angles(0,0,0))
monitorParent:PivotTo(v.CFrame)
ViewPart:PivotTo(ViewPart.CFrame*CFrame.new(0,0,3))
local MonitorUI = script.MonitorUIFolder.UI:Clone()
MonitorUI.Parent = MonitorTemplate
MonitorUI.Adornee = MonitorTemplate.Screen
local MonitorPrompt = script.MonitorUIFolder.MonitorProxTemplate:Clone()
local MonitorPromptValue = v.ExampleMonitor.MonitorValue:Clone()
MonitorPromptValue.Parent = MonitorPrompt
MonitorPrompt.Parent = MonitorTemplate
MonitorPrompt.Adornee = MonitorTemplate
end
end
Here is the hierarchy
Pls help because I tried everything to fix it