Inventory Spy Tool in 3 Minutes

Video tutorial: Roblox Inventory Spy in 3 Minutes! - YouTube

Hi everyone!

People requested that I create a tutorial on an Inventory Spy tool, which can in handy for games like Airport Security checks or Cops and Robbers to determine whether someone has malicious intent or not!

Here, in just 3 minutes, we’ll build an Airport Security checkpoint and also a Police Officer’s metal detector to see into a player’s inventory!

Transcript; written tutorial

Roblox’s client-server model means that players can’t see each other’s inventories (or Backpacks as they’re referred to). This means that if we want to be able to see another player’s inventory, we need to get the server to reach into their backpack and see what’s there.

image

script.DetectorPart.Value.Touched:Connect(function(Hit)
    local Player = game.Players:GetPlayerFromCharacter(Hit:FindFirstAncestorOfClass("Model"))
    if Player then
        local Tools = Player.Backpack:GetChildren()
        print(Tools)
    end
end)

Expected when touching DetectorPart: { ["1"] = "Wand" }

As there are two different methods to achieve the same function, we can assign our code into one function which is called by different event connections – one from the security point and one from the scanner. You’ll notice that I’m connecting up a RemoteFunction here, that’s because we want to make a connection between the client and the server to return a value (in this case a table value).

image

function GetTools(Player)
    local Tools = Player.Backpack:GetChildren()
    return Tools
end

script.DetectorPart.Value.Touched:Connect(function(Hit)
    local Player = game.Players:GetPlayerFromCharacter(Hit:FindFirstAncestorOfClass("Model"))
    if Player then
        local Tools = GetTools(Player)
        print(Tools)
    end
end)

game.ReplicatedStorage.GetTools.OnServerInvoke = function(Player, Victim)
    return GetTools(Victim)
end

Expected when touching DetectorPart: { ["1"] = "Wand" }

To make sure we don’t get bounced results we need to put in some debounces to keep our function’s output consistent, reliable and optimised. We also need to manage the client side. We need the player to click on another player to see their inventory, then we need to display their inventory on some sort of UI.

Seeing a table of items in our output is not what we want, we want players to see it in game. This is done through a UI. As you can see, I think I’ll skip UI design and stick to scripting as I’m clearly better at one than the other.

image
image

-- InventoryService
local DetectorDebounce = false
script.DetectorPart.Value.Touched:Connect(function(Hit)
    if DetectorDebounce == false then
        DetectorDebounce = true
         local Player = game.Players:GetPlayerFromCharacter(Hit:FindFirstAncestorOfClass("Model"))
         if Player then
            local Tools = GetTools(Player)
            print(Tools)
        end

        wait(3)
        DetectorDebounce = false
    end
end)

image

To script this UI is actually pretty simple, as we’re receiving a table value from the server we can just us a for loop to iterate through it. We can then display some properties of that tool, it would be nice to include the tool’s thumbnail as an aesthetic touch as well as the tool’s name. You’ll notice that I’ve gone ahead and cloned a template which is in ReplicatedStorage – all this template does is allow me to easily create new elements in our ScrollingFrame.

-- WandController
script.Parent.Activated:Connect(function()
    local Target = game.Players.LocalPlayer:GetMouse().Target
    if Target then
       local Victim = game.Players:GetPlayerFromCharacter(Target:FindFirstAncestorOfClass("Model"))
        if Victim then
            local Tools = game.ReplicatedStorage.GetTools:InvokeServer(Victim)
            for _, Tool in pairs (Tools) do
                local Frame = game.ReplicatedStorage.ToolTemplate:Clone()
                Frame.Name = Tool.Name
                Frame.ImageLabel.Image = Tool.TextureId
                Frame.TextLabel.Text = Tool.Name
                Frame.Parent = game.Players.LocalPlayer.PlayerGui.Inventory.Frame.Items
            end
        end
    end
end)

You can download this place file and see all of the code files from GitHub in the description below, as well as a link to the DevForum tutorial post. If you have any questions, feedback or opinions about this please don’t hesitate to leave a comment I read and reply to them all. If you want to see another speed tutorial on just about anything, also leave a comment.

If you made it this far, thank you so much for watching. It would be amazing if you could leave a like, as these speed-tutorials are a series I’m running about anything you want! Just leave a comment and I’ll get straight to work making a speed tutorial.

Thank you so much for reading, and I’ll see you in the next one!

11 Likes

Great job! This works very Well!

2 Likes

Thank you! I had a lot of fun making it so looking to do more in the future

1 Like

Walking to police station in da hood

btw nice tutorial but you should add “more comments” to your code next time so peoples can understand

( im all alone in the script editor happy that you have viewers :frowning: )

1 Like

I might test this at some point. Will these work on NPCs, or players only? I don’t know anybody I could test this with.

Edit: Yes it does, just watched the tutorial video. But I must ask, will it also detect items that aren’t in the hotbar as well?

1 Like

nice it help me alot keep groww :heart: :grinning:

1 Like

Thank you so much for checking out the tutorial!

Thanks so much for the feedback also, I definitely agree that more comments would do a long way. From now on I’ll be adding more descriptive comments to my code so it’s easier to follow along!

Thanks so much for checking out my tutorial!

To get this system to work with NPCs would be really tricky because they don’t have the same “Backpack” style of inventory. If your NPCs have an inventory at all, it’s going to be custom made.

Luckily, if you can figure out where the tools and items in the inventory are stored it’s simple to get this mechanic to work:

In the function GetTools(Player) on the server, you’d have to adjust the code to return a table of the NPCs inventory. It could be:

function GetTools(NPC)
    -- Let's compile an array of all tools in the NPCs character model.
    local Tools = {}

    -- Iterate through all the character's children
    for _, Child in pairs (NPC:GetChildren()) do
        if Child:IsA("Tool") then
             -- Insert into our array of tools the tool that is inside the NPC character.
             table.insert(Tools, 1, Child)
        end
    end

    -- Return all the tools we found in their character.
    return Tools
end

This would work work with the rest of the code because we’re returning the exact same value from the function, an array of tools. The method of retrieving those tools is the only thing that’s changed.

Hope this helps,
-Tom :slight_smile:

It’s not that I wanted to check NPCs but wanted to know if it would work on NPCs so I could test it. One other question - will it show items that don’t appear in a players hotbar? They would technically be part of the backpack, or at least I think, but I just wanted to be sure that it worked.

Game Testing Modes | multi-client-simulation (roblox.com)

This is how you can test by using 2 different players, as you said you have no one to test it with.
At the moment, the code that is in the tutorial won’t work for NPCs because we’re using the GetPlayerFromCharacter() method which will return nil for NPCs.

In answer to your other question, sorry for not answering it in the first response, yes it will show people’s whole backpacks including stuff you can’t see in the hotbar.

Hope this helps

1 Like

The github doesn’t work, so this tutorial is caduc.

Uhm I don’t think this tutorial is working anymore. All it does is print a random value which clearly aren’t the name of the tools and since the github page is broken I can’t get the scripts or place file either.

Thanks for this! This tool really helped! I have been looking for quite a bit, now, I’ve found it! I need it for the Military Police Team in my game in order to search if civilians have weapons, It worked!

Hi,

Can you send me a working .rbxl file that you used and has no issues?

Thankd