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:

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!

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

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

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.

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

Answer this question