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

How would I make a script that checks if a player has things in their backpack?

Asked by
Txeer 46
4 years ago

I'm thinking I would need to do something with GetChildren() but I'm not sure what. Any ideas?

1 answer

Log in to vote
0
Answered by
2ndwann 131
4 years ago
Edited 4 years ago

There is a handy way to do this. As you said, GetChildren() is a built-in Roblox function that solves problems like these.

Put this in a LocalScript that's under ReplicatedFirst

local backpack = game:GetService("Players").LocalPlayer:WaitForChild("Backpack")
for name, child in pairs(backpack:GetChildren()) do
    if child:IsA("Tool") then
        if child.Name == "YourNameHere" then -- Replace YourNameHere with the name of the tool you wanna find
        print("Tool Found!")
    end
    end
end)

I hope this helps!

0
@2ndwann why in ReplicatedFirst? Also what even is replicated first Vursatile 12 — 4y
0
@Vursatile, in order for LocalScripts to work, they have to be in ReplicatedFirst or in a Tool. Maybe you should read this: https://developer.roblox.com/en-us/api-reference/class/LocalScript 2ndwann 131 — 4y
Ad

Answer this question