If statement doesn't detect if the object value isn't nil

  1. What do you want to achieve? Keep it simple and clear!
    i’d like to know why my if statement isn’t working
  2. What is the issue? Include screenshots / videos if possible!
    the if statement i’ve made doesn’t detect if the object value isn’t nil
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    couldn’t find any solutions so far

here’s the script

script.Parent.Parent.currentMatchMaker:GetPropertyChangedSignal("Value"):Connect(function()
	if script.Parent.Parent.currentMatchMaker.Value ~= "" or script.Parent.Parent.currentMatchMaker.Value ~= nil then
		script.Parent.Parent.currentMatchMaker.Value.timeLeft.Changed:Connect(function()
			script.Parent.Value = script.Parent.Parent.currentMatchMaker.Value.timeLeft.Value
		end)
	end
end)

output is

You’re trying to access timeLeft in the currentMatchMaker's value.

Correct: script.Parent.Parent.currentMatchMaker.timeLeft.Changed

Try doing ~= nil first.

Also, what is

script.Parent.Parent.currentMatchMaker.Value.timeLeft

Are you sure you didn’t mean

script.Parent.Parent.currentMatchMaker.timeLeft:GetPropertyChangedSignal("Value")

that’s because currentMatchMaker is a object value. in order to get the right timeleft for that currentmatchmaker i have to access the value since the value has timeleft as a child.
my script works fine when the currentmatchmaker has a value

I believe the first condition is the culprit. You should not try to compare objects and strings. Better do this:

if not (script.Parent.Parent.currentMatchMaker.Value == nil) then
		script.Parent.Parent.currentMatchMaker.Value.timeLeft.Changed:Connect(function()
			script.Parent.Value = script.Parent.Parent.currentMatchMaker.Value.timeLeft.Value
		end)
	end

Not to mention, an empty string isn’t the same as a nil value. Nil means it is a completely empty value, not even 0, while an empty string is a string value without characters.

I checked if it was a empty string or not because of in this post the original poster marked the solution as this

if Slot == "" or Slot == nil then

end

also, i tried doing your method and it still gives me that same error

The issue was that the function was giving nil values since the value of currentMatchMaker was nil and its because that function was still connected and wasn’t disconnected so, it just kept running without the if statement being ran again. if i were to use RBXScriptSignal:Once() then it would only run once and wouldn’t update what i wanted it to do is let the function connected when currentMatchMaker has a value.

My solution was to disconnect the function thing when the value of currentMatchmaker is nil.

Fixed version with no errors

local connection

script.Parent.Parent.currentMatchMaker:GetPropertyChangedSignal("Value"):Connect(function()
	if script.Parent.Parent.currentMatchMaker.Value then
		connection = script.Parent.Parent.currentMatchMaker.Value.timeLeft.Changed:Connect(function()
			script.Parent.Value = script.Parent.Parent.currentMatchMaker.Value.timeLeft.Value
		end)
	elseif not script.Parent.Parent.currentMatchMaker.Value then
		connection:Disconnect()
	end
end)