Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

1 answer

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!

2 comments

0

@2ndwann why in ReplicatedFirst? Also what even is replicated first

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

This discussion is preserved as it was. New answers, comments, and votes are closed.