How to check if the ObjectValue's Value exists

In that case if value.Value then should work.

could you provide more context? what specific error is it printing out?

1 Like

3 people asked this already and he still didn’t show the error. He does not understand, that error provide more information than the

1 Like

I’m trying to check if the block still exists, the error is related to that. Also I’m confused what is pcall? And where do I put it?

while true do
	task.wait(.5)
	local success,error = pcall(function()
		local part = script.Parent.Value 
	end)
	if script.Parent.Value ~= nil then
		if success then
			script.Parent.Parent.Input.Value = script.Parent.Value.Output.Value -- Errors here
		end
	end
end

and here is the error at line 8
Output is not a valid member of Part "Switch"

You don’t need pcall here. It just catches errors and preventing script from being stopped.

while true do
   task.wait(.5)
   if script.Parent.Value ~= nil and script.Parent.Value.Output.Value ~= nil then
      script.Parent.Parent.Input.Value = script.Parent.Value.Output.Value
   end
end

its giving the same error except now on the if statement

could you send a screenshot of your explorer with the script and it’s decedents?


Where is the Output Value?

the output value is inside the poweredfrom value’s block

Try this

while true do
	task.wait(.5)
	if script.Parent.Value ~= nil then
		if script.Parent.Value:FindFirstChild("Output") then
			script.Parent.Parent.Input.Value = script.Parent.Value.Output.Value
		end
	end
end
script.Parent.Changed:Connect(function(obj)
	if obj ~= nil then
		if obj:FindFirstChild("Output") then
			script.Parent.Parent.Input.Value = script.Parent.Value.Output.Value
		end
	end
end)

Use .Changed Event to check if the value changed.

Can you send a picture of this?

When you bind an instance to an objectvalue and when the instance is destroyed, the objectvalue will still be spoofed despite the fact that the instance no longer exists, so the only way to check this is to see if the objectvalue is a descendant of a particular service. (e.g:

print(ObjectValue.Value:IsDescendantOf(workspace))

Prints True if the object still exists or False if the object has been destroyed.)

1 Like

Instead, do

print(ObjectValue.Value.Parent)

If the Value was destroyed, it will print nil. So…

if ObjectValue.Value.Parent then

Is the solution to how to check if an objectvalue’s value still exists :partying_face:
“Absence of true” is “false”, which means that both false and nil will evaluate as non-true.

Oh my god why have a loop for this?

script.Parent.Value.Changed:Connect(function()
    if script.Parent.Value == nil then return end -- If it's nil then just end the function here.

    -- Code here
end)
1 Like