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

How do i scan the players inventory then place the item names on a label?

Asked by 5 years ago

Im trying to make a admin gui and I want to be able to scan the players backpack then put the items in a frame with a few text labels.

1 answer

Log in to vote
1
Answered by
DanzLua 2879 Moderation Voter Community Moderator
5 years ago

This isn't a request site, but I will give you a basic idea of what to do

You want to run through each child of their backpack and create a textlabel using a for loop

local plr=--plr
local frame=--where we put the textlabels

local equipped=false
if plr.Character:FindFirstChildOfClass("Tool") then
    local t=Instance.new("TextLabel")
    t.Position=UDim2.new(0,0,0,0)
    t.Text=plr.Character:FindFirstChildOfClass("Tool").Name
    t.Parent=frame

    equipped=true
end
for i,thing in pairs(plr.Backpack:GetChildren()) do
    local t=Instance.new("TextLabel")
    t.Position=UDim2.new(0,0,0,t.Size.Y.Offset*(i +(equipped and 1 or 0))
    t.Text=thing.Name
    t.Parent=frame
end

SO what did I do? I first set my variables and then checked if the player is holding a tool, if so I created a textlabel for that and set the equipped variable to true

I then went through every instance in their backpack and created a textlabel for that adjusting the position as i went along and accounted for that first textlabel if there was one.

You can remove this part and use one of roblox's automatic ui instances to do this for you.

0
DanzLua, this wont work when i have more than one tool in my backpack... unless i just did somthing wrong deadwalker601 110 — 5y
0
@deadwalker601 Can you check if it's a positioning problem and the textlabels are being parented correctly? (check how many textlabels there are) DanzLua 2879 — 5y
Ad

Answer this question