How To Check If Something Exists

No im checking if the player has the int value called “Quest” not the value of it

script.Parent.MouseClick:Connect(function(player)
    if not player:FindFirstChild("Quest") then
        local newQuest = Instance.new('IntValue',player)
        newQuest.Name = 'Quest'
    end
end)

Is this what you were trying to achieve?

Yea, i had something similar to it, however it didnt work for some reason

Oh, alright. Try that one out.

It didn’t work could it be that i am trying to check if 2 values exist?
i forgot to add that im also checking for another intvalue

script.Parent.MouseClick:Connect(function(player)
    if not player:FindFirstChild("Quest") or ("Tutorial") then
        local newQuest = Instance.new('IntValue',player)
        newQuest.Name = 'Quest'
    end
end)

Are you using a LocalScript or a normal Script (server script)?

That would’ve helped form the start. This is the setup you should have.

image

Yes, it is possible to do that with both of those values.

script.Parent.MouseClick:Connect(function(player)
	if not player:FindFirstChild("Quest") or player:FindFirstChild("Tutorial") then
		local newQuest = Instance.new('IntValue',player)
		newQuest.Name = 'Quest'
	end
end)

Oh so i need to add FindFirstChild for the 2nd value? let me see if it works

Sorry just to clarify, you want them to be able to get the quest whilst they have the tutorial or not?

So if they have the tutorial i dont want them to get a quest

Alright, use this.

script.Parent.MouseClick:Connect(function(player)
	if not player:FindFirstChild("Quest") and not player:FindFirstChild("Tutorial") then
		local newQuest = Instance.new('IntValue',player)
		newQuest.Name = 'Quest'
	end
end)
1 Like

Computers are dumb, so you have to be explicit in what you order it to do.
So, while your line here makes sense to humans:

 if not player:FindFirstChild("Quest") or ("Tutorial") then

the second logical argument (“Tutorial”) will just return true always.

You see, an IF statement simply checks if something is true or exists;
So the following…

if "" then -- string value (exists)
if 1 then -- number value (exists)
if game.Workspace then -- instance (exists)

are the same as saying…

if true then -- bool value

because all of the above are valid values - they exist
whereas…

if nil then -- nil / null (doesn't exist)
if game.Workspace:FindFirstChild("SomethingThatDoesntExist") then -- nil instance (doesn't exist)

are the same as

if false then -- bool value (exists, but is false - so the following code will never run)
1 Like