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

How to check any item in a players backpack?

Asked by 5 years ago

Everything in the script works how I want it to, but when you try to check any players other than yourself, it won't print anything back to the interface? I suspect it has something to do with the local player value that I set to localplayer but I don't know how to fix it.

Thanks, fravls

-- The four commands are open to open the GUI, close to close the GUI, clear to clear the text and !check insertusername to get a list of player's inventory

function invcheck()
        wait(2)
game.Players.LocalPlayer.Chatted:Connect(function(msg)

local player = game.Players.LocalPlayer
local inventory = player.Backpack
local items = inventory:GetChildren()
player.PlayerGui.ScreenGui.invtext.title.Text = (player.Name .. " inventory:")




for i= 1,#items do wait(1)
local backpack = {items[i]}
local a = items[1]
local b = items[2]
local c = items[3]
local d = items[4]
local e = items[5]
local f = items[6]
local g = items[7]
local h = items[8]
local j = items[9]
local k = items[10]
local l = items[11]
local m = items[12]
local n = items[13]
local o = items[14]

-- add items in this pattern above then add it into the allitems table down below 
local allitems = {a,b,c,d,e,f,g,h,j,k,l,m,n,o}



    if msg == ("!check " .. player.name )
    then print (allitems[i]) 

player.PlayerGui.ScreenGui.invtext.Text = (allitems[i].Name)






end 
end
end)
end

game.Players.PlayerAdded:Connect(invcheck())


game.Players.LocalPlayer.Chatted:Connect(function(msg)


    if msg == "close" then 
game.Players.LocalPlayer.PlayerGui.ScreenGui.invtext.Text = " " 
game.Players.LocalPlayer.PlayerGui.ScreenGui.invtext.Visible = false


end
end)


game.Players.LocalPlayer.Chatted:Connect(function(msg)
    if msg == "open" then
game.Players.LocalPlayer.PlayerGui.ScreenGui.invtext.Visible = true
end
end)    

game.Players.LocalPlayer.Chatted:Connect(function(msg)
    if msg == "clear"
    then game.Players.LocalPlayer.PlayerGui.ScreenGui.invtext.Text = " "

end
end)
0
please ignore my messy code Im sorry im novice Frandavi1000 15 — 5y
0
wth TheluaBanana 946 — 5y
0
is this egyptian TheluaBanana 946 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

u can do dis boi; place in starterpack or something

local player = game.Players.LocalPlayer
local backpack = player.Backpack
player.CharacterAdded:connect(function()
    for i, v in pairs(backpack:GetChildren()) do
        print(v)
    end
end)

this will print the contents of the backpack when the backpack's player's character joins. Alternately, if u want to print everyone's stuff, u can do something like this(place in workspace):

wait(1) -- wait for stuff to load

for i, player in pairs(game.Players:GetChildren()) do -- players
    for i, backpack in pairs(player:GetChildren()) do
        if backpack.Name == "Backpack" then -- backpacks
            for i, v in pairs(backpack:GetChildren()) do -- stuff in backpacks
                print(v)
            end
        end
    end
end
Ad

Answer this question