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

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

Asked by 4 years ago

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

(plr = the player)

1st attempt:

1if  plr.Backpack["Building Tools"] == true then
2        print("btools")
3    else
4            print("no btools")
5end

and then my 2nd attempt:

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

Is there a way? All help is appreciated!

0
findfirstchild raid6n 2196 — 4y
0
if plr.Backpack["Building Tools"] then blah blah blah end Block_manvn 395 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago

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

1if  plr.Backpack:FindFirstChild("Building Tools") then --You dont need to double check it,as it returns the value
2            print("btools")
3        else
4                print("no btools")
5    end
Ad
Log in to vote
0
Answered by 4 years ago

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

1local instance = object:FindFirstChild("whatyouaretryingtofind")
2if instance then --true
3    --your code here
4else -- false
5    --your code here
6end
0
that method doesn't work WideSteal321 773 — 4y

Answer this question