Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

ScrollbarFrame not showing items properly?

Asked by
Cuvette 246 Moderation Voter
8 years ago
Edited 8 years ago

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.

01local itemTemplate = script.Parent.Item
02player = script.Parent.Parent.Parent.Name
03items = {}
04itemY = -50
05 
06while true do
07local backpackItems = game.Players[player].Backpack:getChildren()
08    for i=1,#backpackItems do
09        table.insert(items, backpackItems[i].Name)
10        itemY = itemY + 50
11        print(player .. " has " .. items[i])
12            if #items <= #backpackItems then
13                local a = itemTemplate:Clone()
14                a.Parent = script.Parent.ScrollingFrame
15                a.Position = UDim2.new(0, 0, 0, itemY)
View all 23 lines...

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

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

Log in to vote
1
Answered by 8 years ago
Edited 8 years ago

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()

0
Well that literally just fixed everything, Thanks for that! Cuvette 246 — 8y
Ad
Log in to vote
1
Answered by 8 years ago
01itemTemplate = script.Parent.Item
02items = {}
03NewPos = UDim2.new(0,0,0.1,0) -- X.Scale, X.Offset, Y.Scale, Y.Offset.
04game.Players.LocalPlayer.Backpack.ChildAdded:connect(function() -- Fires when child is added
05        script.Parent.ScrollingFrame:ClearAllChildren()     --Clears all children
06        for i = 1,#items do
07            table.remove(items,i) -- Clears the table
08        end
09        for i,v in pairs (game.Players.LocalPlayer.Backpack:GetChildren()) do -- Grabs all tools
10            print(v.Name)
11            table.insert(items,#items+1,v.Name) -- Inserts into table
12                local a = itemTemplate:Clone()
13                a.Parent = script.Parent.ScrollingFrame
14                a.Position = a.Position + NewPos
15                a.Text = items[i]
16                a.Visible= true
17                a.Name = v.Name
18        end
19end)

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!

Answer this question