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

Is there a way to detect if something does/doesn't exist?

So i have tried 2 different ways, neither of them work.

(plr = the player)

1st attempt:

if  plr.Backpack["Building Tools"] == true then
		print("btools")
	else
	        print("no btools")
end

and then my 2nd attempt:

if  not plr.Backpack["Building Tools"] == nil then
		print("btools")
	else
	        print("no btools")
end

Is there a way? All help is appreciated!

2 comments

0

findfirstchild

0

if plr.Backpack["Building Tools"] then blah blah blah end

2 answers

✓ Accepted answer

Use FindFirstChild function,if it finds the targeted object,it returns true else it returns false

if  plr.Backpack:FindFirstChild("Building Tools") then --You dont need to double check it,as it returns the value
	        print("btools")
	    else
	            print("no btools")
	end

Hello, a way you can check if an instance is inside another, you can do this.

local instance = object:FindFirstChild("whatyouaretryingtofind")
if instance then --true
	--your code here
else -- false
	--your code here
end

1 comment

0

that method doesn't work

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