Question, why is this doing this

so, Why is there 8 viewportframes in the clone when it finishes?

for i = 1, #Characters do
	print(i)
	if Characters[i]:IsA("Model") and Characters[i]:FindFirstChild("Humanoid") then
		NameNumber += 1
		local Clone = ScrollingFrame.temp:Clone()
		Clone.Name = NameNumber
		Clone.Parent = ScrollingFrame
		local viewportFrame = Instance.new("ViewportFrame")
		viewportFrame.Size = UDim2.new(1, 0, 1, 0)
		viewportFrame.Position = UDim2.new(0, 0, 0, 0)
		viewportFrame.BackgroundColor3 = Color3.new(1, 1, 1)
		viewportFrame.Parent = ScrollingFrame.temp
		local UICorner = Instance.new("UICorner")
		UICorner.Parent = viewportFrame
		local part = Characters[i]:Clone()
		part.Parent = viewportFrame
		print(part.HumanoidRootPart.Position,Characters[i].Name)
		local viewportCamera = Instance.new("Camera")
		viewportFrame.CurrentCamera = viewportCamera
		viewportCamera.Parent = viewportFrame
		viewportCamera.CFrame = CFrame.new(Vector3.new(part.Head.Position.X,part.Head.Position.Y-1,part.Head.Position.Z - 3), Vector3.new(part.Head.Position.X,part.Head.Position.Y-1,part.Head.Position.Z))
		if NameNumber == 1 then
			Clone:Destroy()
		end
	end
end

anything helps,

1 Like

Unsure if this is it, but try converting this for loop into an in pairs loop and see if it fixes it. There’s nothing wrong with the current script but maybe changing the type of loop can fix it, or at least give you more insight into the problem.

1 Like

the in pairs loop isn’t working, idk what the problem could be.

Also Idk if this matters, but it doesn’t work in the first loop around.

It’s a bit difficult to visualize what’s going on just from the code you provided, but it might be that you’re mistaking the ‘ScrollingFrame.temp’ object for the new Clone of it.

For every iteration in the loop, it seems like you parent the new ViewportFrame to the original temporary object:

My guess is that you meant to do:

viewportFrame.Parent = Clone
1 Like

btw why is there always one viewportframe that not works?

I think that’s the original object you’re cloning: ‘ScrollingFrame.temp’. What you can do is delete it after you’re done making your clones and you can compensate by just creating one more clone beforehand. Glad it works!

I did that on the after the loop

ScrollingFrame.temp:Destroy

Is the one that doesn’t work the same name as the others?

Nevermind, It was a problem with one of the models

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.