Would this work to get a players tools:
game.Player.LocalPlayer.Backpack:GetChildren()
Would this work to get a players tools:
game.Player.LocalPlayer.Backpack:GetChildren()
I would not recommend using a local script to modify a players Backpack. Use a serverscript and then create a loop that loops through all players and then check for the certain player you want, then create another loop to go through the backpack and then you can do what ever you need to do, from adding items to removing them.
So in a server script I do
game.Player.PlayerName.Backpack:GetChildren()
No, I donât believe that would work. Could you tell me what youâre trying to do?
list a players tools for a security scanner.
Okay, how does this security scanner detect anything? Does it used the .Touched event?
If so, you can then loop through that players Backpack printing each Item.
But how do I loop through?
for I,v in pairs(game.Player.PlayerName.Backpack:GetChildren()) do
We are getting to that, I need to know how the security scanner works, so we can integrate the for loop.
If its using the Touched Event, once that is fired you can do:
local hitParent = game.Players:GetPlayerFromCharacter(hit.Parent)
for i,v in pairs (hitParent:GetChildren) do
--Then u do the stuff in here to find backpack
end
How do we find backpack? Can you show me how to print each tool?
To just print the name of the tools, you would do something like this (borrowing from the example from @Haukly ):
local hitParent = game.Players:GetPlayerFromCharacter(hit.Parent)
for i,v in pairs(hitParent:GetChildren()) do
print(v.Name) -- Inside the loop, you would print the name.
end
end
And itâll print every toolâs Name?
Affirmative. This code will print every tool name within the playerâs backpack.
I get an error saying attempt to index nil âGetChildrenâ
This script should be inside the sensor. This is a more perfected version, and might as well be the entire script.
script.Parent.Touched:Connect(function(hit)
local h = hit.Parent:findFirstChild("Humanoid")
if h ~= nil then
local player = game.Players:GetPlayerFromCharacter(h.Parent)
if player then
for i, tools in pairs(player.Backpack:GetChildren()) do
print(tools.Name)
end
end
end
end)
I also realized where I went wrong, I forgot to identify the path to the backpack. The more perfected script right above this reply does account for that, however. What can I say? Trial and error.
I think you mean FindFirstChild
Nothing printed
Do you have any tools to begin with? If so, are there any errors in the output?
I have 1 tool, and no errors. (30 chars)
After if h ~= nil then
, I added print(âhâ), and when I touched, h was not printed.
That makes me wonder. Is this a card or are you scanning the player?
Edit:
Furthermore, try doing h.Name, as h is an instance, and not always is it able to be printed.