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.
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).
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.
-- 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)
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!