How To Check If Something Exists

I want to make it where if a player has this int value you can’t run the rest of the script. However, when the player doesn’t have the value, the player is unable to run the rest of the script. So basically if the player doesn’t have the “Quest” value then they should be able to print, however, that is not the case here.

if player:FindFirstChild("Quest") then return end
    print("1")

What value are you trying to return?

If i am being honest, im still pretty new to scripting, some guy said to add return there from a previous post

I Am not good in the return thing but Usually you return a function and not end

You should try this out, maybe it will work better.

would i just add “if not” to make it where if u do have the “Quest” value it wouldnt print?

When you do If not you need to define what is yes so what will be not?

returns are used in functions to send data or stop functions

1 Like

Exactly but for some reason i cant run the script even when i dont have the “Quest” value. I want it where if u have the “Quest” Value then the script will stop

script.Parent.MouseClick:Connect(function(player)
    if player:FindFirstChild("Quest") then return end
        print("1")

maybe add else to if statement?

script.Parent.MouseClick:Connect(function(player)
    if player:FindFirstChild("Quest") then
           print("Player has quest") 
    else
           print("Player does not have quest")
    end
end)

You need to denote player and add a suitable function to call return end in:

game.Players.PlayerAdded:Connect(function(player)
	if player:WaitForChild("Quest") then 
		print("1")
	else
		print("nil")
	end
end)

As shown here, it waits until a player has joined, then if they have Quest, it prints 1 and if they don’t, it prints nil. Use a PlayerAdded function before adding mouseClick, just to see if it actually works.

Just putting ..Parent.MouseClick won’t work, because there is no ClickDetector associated with it.

The script’s parent is the click detetcor

I never expected there to be, I was simply correcting his code stated above where he did use a click detector.

Oh I see, disregard my last comment then.

Keep with my code, see if the check function works, and then replace my function call with your click one.

Thats weird, so i do get prints, but the problem is that i dont have the quest value and yet its printing “1”

	if player:FindFirstChild("Quest") then 
		print ("1")
	else
		print("2")

How are you adding the quest value to the player in the first place?

In the script with an Instance.new

So basically the script makes a quest value then if u already have a quest value then u cant get another one. Because whats happening is that i can spam click the npc and get multiple quest values

Do you mean like checking the Quest Int value and if value is greater than 0, then you don’t want to run the rest of the function?