How To Check If Something Exists

So I want to make it if you have this int value you can’t click on the NPC. However, it says in the output that the player does not have the value “Quest” which is true and the rest of the script doesn’t run. I want to make it where if you did have the value u cant click on the NPC but if u don’t u can.

if player.Quest  then end
2 Likes

use findfirstchild(“”) to check if it exists

1 Like

You can use FindFirstChild to check if that particular object exists as a Child inside the Instance, that you used FindFirstChild on.

I don’ know if this is what you wanted to do, but it can be done like this:

if player:FindFirstChild("Quest") then 
   print("Exists") --This will run only when theres something called "Quest" as a child of player instance.
end

How would I make it where if you do have the value you can’t run the rest of the script? This is what I currently have. It doesn’t work tho.

if player:FindFirstChild("Quest") then end

Try

something:Connect(function(player)
  if player:FindFirstChild("Quest") then return end
  print("Quest does not exists")
end)

I tried it, but for some reason my script doesnt run now, and i dont have the Quest Value

That’s because it uses return which cancels the rest of the function.

Currently I have this, however it doesnt work

if player:FindFirstChild("Quest") then end

Is the rest of your logic inside the if statement like this:

if player:FindFirstChild("Quest") then
-- do whatever logic here
end

or are you doing:

if player:FindFirstChild("Quest") then end
-- do whatever logic here

like this

if player:FindFirstChild("Quest") then end

You need to make sure that you have the actual logic inside the if statement:

if player:FindFirstChild("Quest") then -- This means we found the quest object so we will continue whatevers in the if statement
-- do whatever logic here
end

or make it return (which stops the function) if the quest value doesn’t exist (similar to what @dollychun suggested but making sure to stop the function if its false)

if not player:FindFirstChild("Quest") then return end -- This means the quest object wasnt found and therefore the rest of the thread won't continue.
3 Likes