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

How can you detect if someone doesn't have a tool?

Can someone just give me a explanation please? A website would be useful if there is one.

Thanks, Nathan.

2 answers

The Official Roblox Wiki (wiki.roblox.com) is always a good place to start looking for ideas.

Okay, here's a simple and effective way to check if players don't have a tool (does not work very well standalone, does need to be put into a larger script to be of use)

for i,v in pairs(game.Players:GetChildren()) do --create a list of players
	if not v.Backpack:findFirstChild("INSERT TOOL NAME") then --check for the tool
		--Do whatever you need to do now.
	end
end

Alternatively, if you want to check if a specific player has a tool, you can do the following:

for i,v in pairs(game.Players:GetChildren()) do
	if v.Name == "PLAYERNAME" and not v.Backpack:findFirstChild("TOOLNAME") then
		--Do whatever you need to do now.
	end
end

You could make an if statement figuring if the tool instance is in their backpack. Or if you want to detect if they've equipped it then check in their character.

Checking in backpack;

player = "Player Name Here" --Specify the player's name
tool = "Tool Name Here: --Specify the tool's name
plr = game.Players:FindFirstChild(player)
if (plr ~= nil) then --Check if they exist
	c = plr.Backpack:GetChildren() --Get all the children of their backpack
	for i = 1,#c do --iterate through the children of the backpack
		if c[i].Name:lower() == tool:lower() then --check if theres a match to the tool name
			print("Tool found!")
		else
			print("Tool not found :(")
		end
	end
end			

This would print 'Tool not found :(' if there was no tool. Sorry if the 'c[i].Name:lower == tool:lower()' confused you. That was just checking if both names matched in lowercase, used for typos in the tool name.

Checking in the character;

player = "Player Name Here" --specify the player's name
tool = "Tool name here" --Specify the tool's name
plr = game.Workspace:FindFirstChild(player) --Find them in the workspace
if (plr ~= nil) then --Check if they exist
	if plr:FindFirstChild(tool,true) then --Check if the tool is in the character
		print("Tool found!") --if it is then print this
	else
		print("Tool not found :(") -- if not print this
	end
end

This would effectively check if they have the tool equipped or not. Same results as the first script. Same method really, find the place where it would potentially be in, search through the children of that place, if theres a match then do something. Pretty simple and gets fun when you get the hang of it(:

Hope I helped

+1

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