Checking for nil being weird

I’m trying to make it so when 2 object values are checked and they are both nil, it will say “No people!” but it doesn’t. instead its ignored and when one of the values is not nil, it says “No people!”

if mem1.Value and mem2.Value == nil then
		displaytext.Text = "No people!"
		wait(1)
	else
		displaytext.Text = "Teleporting..."
		wait(1)
	end

I don’t know if I’m just getting this wrong or this is a Roblox glitch.

2 Likes

The issue’s here, just a slight logic error. Comparing it once won’t compare for both, so you’re just saying “if mem1’s value exists and mem2’s value is nothing”.

Instead, do this:

if mem1.Value == nil and mem2.Value == nil then

but we can simplify that with a logic statement to just this:

if not mem1.Value and not mem2.Value then
1 Like

Oh I completely forgot you had to do that. thanks

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.