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
7 years ago
Edited 7 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.

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;

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 7 years ago
Edited 7 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 — 7y
Ad
Log in to vote
1
Answered by 7 years ago
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!

Answer this question