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

Why won't my pairs loop get all instead it only gets one?

I'm not sure if I'm missing something right in front of me but, I have a folder where it'll get the children of and run the loop for pairs but instead it'll only get one instead of them all?

function CreateDisplay(Weapon, ViewFrame)
	print("Create Display Function")
	local Display = Displays.Weapons:WaitForChild(Weapon):Clone()
	Display.Name = "Model"
	Display.Parent = ViewFrame

	local Camera = Instance.new("Camera", ViewFrame)
	ViewFrame.CurrentCamera = Camera

	local CameraPosition = Vector3.new(0,0,4)
	Camera.CFrame = CFrame.new(Display.PrimaryPart.Position + CameraPosition)

	while true do
		if ViewFrame:FindFirstChildOfClass("Model") then
			Display:SetPrimaryPartCFrame(Display:GetPrimaryPartCFrame()*CFrame.fromEulerAnglesXYZ(0,.025,0))
			wait()
		else
			break
		end
	end
end

function CreateList()
	print("Create List Function")
	for Index, Found in pairs(game.ReplicatedStorage.AvailableTags.Legal:GetChildren()) do
		print(Found.Name)
		local ItemClone = Template:Clone()
		ItemClone.Visible = true
		ItemClone.Name = Found.Name
		ItemClone.Parent = List
		CreateDisplay(ItemClone.Name, ItemClone)
		ItemClone.Select.MouseEnter:connect(function()
			ItemClone.Select.TextColor3 = Color3.new(255/255, 170/255, 0/255)
		end)
		ItemClone.Select.MouseLeave:connect(function()
			ItemClone.Select.TextColor3 = Color3.new(255/255, 255/255, 255/255)
		end)
		ItemClone.Select.MouseButton1Click:connect(function()
			if game.ReplicatedStorage.AvailableTags.Legal:FindFirstChild(ItemClone.Name) then
				print("Select Item")
			end
		end)
	end
end

4 comments

0

I'm Not Quite Sure What You Mean, Wheres The Line Relevant To Your Case?

0

Alright sorry for not thoroughly explaining my issue, but let me start here. The purpose of this code is to create a list based off of a folders children into a ScrollingFrame. So as you can see, I have a loop there that'll create a display for each instance found within that folder right? So going from there my issue is it'll only create one when there's five instances.

0

Are you sure you put a UIGridLayout in the scrolling frame?

0

I'm using a UIListLayout, but from what I'm seeing from it likewise it only creates one instance whereas I don't see any issues in my code unless I'm missing something right in front of me.

1 answer

I've found the issue to my problem, and what the predicament had been was my loop to rotate the model of the display. So what I had done to fix this was, completely remove that loop and then separately moved it into it's own function and calling on that function after the display is created something along the lines of this.

function RotateDisplay(Display, ViewFrame)
    while true do
        if ViewFrame:FindFirstChildOfClass("Model") then
            Display:SetPrimaryPartCFrame(Display:GetPrimaryPartCFrame()*CFrame.fromEulerAnglesXYZ(0,.025,0))
            wait()
        else
            break
        end
    end
end

function CreateDisplay(Weapon, ViewFrame)
    print("Create Display Function")
    local Display = Displays.Weapons:WaitForChild(Weapon):Clone()
    Display.Name = "Model"
    Display.Parent = ViewFrame

    local Camera = Instance.new("Camera", ViewFrame)
    ViewFrame.CurrentCamera = Camera

    local CameraPosition = Vector3.new(0,0,4)
    Camera.CFrame = CFrame.new(Display.PrimaryPart.Position + CameraPosition)

	RotateDisplay(Display, ViewFrame)
end

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