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

How do I make it so it will adapt when taken away?

Asked by 7 years ago

Im trying to make an inventory system but i cant figure out how to make ### Gui adaptive on its own. like someone picks up something I need it to add a label then when they drop it it removes it and moves everything up. I know how to make my script below add one when I pick something up but how do I make it adapt when I drop something?

-- A neat way to store all your buttons
local Buttons = {}

-- Assuming this is where the scrolling frame is
local Scroll = script.Parent

-- Create a new button
local function NewButton()

    -- Parent the button
    local Button = Instance.new("TextButton",Scroll)

    -- Make sure you size it before you position it
    Button.Size = UDim2.new(1,0,0,25)

    -- Position the button based off the amount created, times it's Y offset size
    Button.Position = UDim2.new(0,0,0,#Buttons*Button.Size.Y.Offset)

    -- Return the button
    return Button
end

-- Create one every 1 second
while wait() do

    -- Created a new button which is already sized, positioned, and parented.
    local Button = NewButton()

    -- If the button's Position Y Offset plus it's Size Y Offset is greater than the ScrollingFrame's AbsolutePosition Y, then ...

    if Button.Position.Y.Offset+Button.Size.Y.Offset > Scroll.AbsoluteSize.Y then

        -- Set the canvas size to the product of buttons and it's individual size Y offset, plus it's original size (since the first button created is at position 0,0,0,0)
        Scroll.CanvasSize = UDim2.new(0,0,0,#Buttons*Button.Size.Y.Offset+Button.Size.Y.Offset)

    -- If it doesn't exeed the scroll frame, then...
    else

        -- Set it's scrolling size back to 0.
        Scroll.CanvasSize = UDim2.new(0,0,0,0)
    end

    -- Insert the button to the table.
    Buttons[#Buttons+1] = Button
end
0
Anyone? Stephenthefox 94 — 7y

Answer this question