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

ScrollbarFrame not showing items properly?

Hi, I've made a scrollbar frame that is supposed to list every item in the players backpack. Ill show you what I've done so far before I explain what is wrong.

And just for reference if you're going to post an answer where it checks if a certain item exists in the backpack then doesn't add it again... The player can have more than one of that item if they wish.

local itemTemplate = script.Parent.Item
player = script.Parent.Parent.Parent.Name
items = {}
itemY = -50

while true do
local backpackItems = game.Players[player].Backpack:getChildren()
    for i=1,#backpackItems do
        table.insert(items, backpackItems[i].Name)
        itemY = itemY + 50
        print(player .. " has " .. items[i])
			if #items <= #backpackItems then
       			local a = itemTemplate:Clone()
        		a.Parent = script.Parent.ScrollingFrame
        		a.Position = UDim2.new(0, 0, 0, itemY)
       		 	a.Text = items[i]
				a.Visible= true
   			 end
		end
    items = {}
    itemY = 0
wait(0.5)
end

There are a few bugs I can get my head around ill list them here;

  • Also I have to clear the table each loop to allow it to add more items, otherwise it thinks you've got 4 pickaxes when you could have two. Which causes there to be an unlimited amount of text buttons (Image below)

https://gyazo.com/da4bdd21dce7f455b2a72e88ca5db59f

I've definitely gone horribly wrong somewhere and can quite work out ways around this. Maybe i'm just too tired at the moment, who knows?

But anyway if you've got any idea on how to fix this ill greatly appreciate it! Thanks, Cuv

2 answers

✓ Accepted answer

In your while loop, you set the itemY to 0 when you actually want it set to -50.

Before the wait(0.5), change itemY = 0 to itemY = -50

You should probably clear the ScrollingFrame every loop to make sure you don't have thousands of text buttons.

Soo, after the wait(0.5), script.Parent.ScrollingFrame:ClearAllChildren()

1 comment

0

Well that literally just fixed everything, Thanks for that!

itemTemplate = script.Parent.Item
items = {}
NewPos = UDim2.new(0,0,0.1,0) -- X.Scale, X.Offset, Y.Scale, Y.Offset.
game.Players.LocalPlayer.Backpack.ChildAdded:connect(function() -- Fires when child is added
		script.Parent.ScrollingFrame:ClearAllChildren()		--Clears all children
		for i = 1,#items do 
			table.remove(items,i) -- Clears the table
		end
		for i,v in pairs (game.Players.LocalPlayer.Backpack:GetChildren()) do -- Grabs all tools
			print(v.Name)
			table.insert(items,#items+1,v.Name) -- Inserts into table
			 	local a = itemTemplate:Clone() 
	            a.Parent = script.Parent.ScrollingFrame
	            a.Position = a.Position + NewPos
	            a.Text = items[i]
	            a.Visible= true
				a.Name = v.Name 
		end
end)

So basicly, read my notes, You can create this function in general, but .changed doesnt want to work. Maby just a bug.

And please, DONT use space, press the tab button once.... thanks!

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