Is there a way to shorten the length of this script, or make it more efficient?
I'm trying to make my own inventory, so far so good. But to me, this script that updates the inventory seems very long, and inefficient. Is there any way I can improve it?
01 | local plr = game.Players.LocalPlayer |
02 | local buttons = script.Parent.IFrame:GetChildren() |
03 | local items = plr.Backpack:GetChildren() |
04 | local iframe = script.Parent.IFrame |
09 | iframe.Button 1. Visible = true |
10 | iframe.Button 1. ItemName.Value = items [ 1 ] .Name |
11 | iframe.Button 1. Text = items [ 1 ] .Name |
12 | elseif #items = = 2 then |
13 | iframe.Button 1. Visible = true |
14 | iframe.Button 1. ItemName.Value = items [ 1 ] .Name |
15 | iframe.Button 1. Text = items [ 1 ] .Name |
16 | iframe.Button 2. Visible = true |
17 | iframe.Button 2. ItemName.Value = items [ 2 ] .Name |
18 | iframe.Button 2. Text = items [ 2 ] .Name |
19 | elseif #items = = 3 then |
20 | iframe.Button 1. Visible = true |
21 | iframe.Button 1. ItemName.Value = items [ 1 ] .Name |
22 | iframe.Button 1. Text = items [ 1 ] .Name |
23 | iframe.Button 2. Visible = true |
24 | iframe.Button 2. ItemName.Value = items [ 2 ] .Name |
25 | iframe.Button 2. Text = items [ 2 ] .Name |
26 | iframe.Button 3. Visible = true |
27 | iframe.Button 3. ItemName.Value = items [ 3 ] .Name |
28 | iframe.Button 3. Text = items [ 3 ] .Name |
29 | elseif #items = = 4 then |
30 | iframe.Button 1. Visible = true |
31 | iframe.Button 1. ItemName.Value = items [ 1 ] .Name |
32 | iframe.Button 1. Text = items [ 1 ] .Name |
33 | iframe.Button 2. Visible = true |
34 | iframe.Button 2. ItemName.Value = items [ 2 ] .Name |
35 | iframe.Button 2. Text = items [ 2 ] .Name |
36 | iframe.Button 3. Visible = true |
37 | iframe.Button 3. ItemName.Value = items [ 3 ] .Name |
38 | iframe.Button 3. Text = items [ 3 ] .Name |
39 | iframe.Button 4. Visible = true |
40 | iframe.Button 4. ItemName.Value = items [ 4 ] .Name |
41 | iframe.Button 4. Text = items [ 4 ] .Name |
46 | plr.Backpack.ChildAdded:connect(updateinven) |
47 | plr.Character.ChildAdded:connect(updateinven) |