How to check if the ObjectValue's Value exists

Hello, I’m trying to use object values to link/wire two objects together.

Well it works for the most part, but when someone deletes the power source the script errors and you cant wire to it again.

I have looked online.


“PoweredFrom” would be the object value.

Can’t you do if ObjectValue.Value then?

gives me the same error at line 5

What’s the error?
And instead of running a loop, you should just connect an event to value.Changed

what is the “value” in this situation

Just an example, every value has a .Changed event. You can use that in your script for detecting changes

wouldn’t work

aghhhhhhhhhhhhhhhhhh

Well, I don’t really understand your code and what its supposed to do, can you provide the logic for it?

keep in mind that the value works until the power source is deleted then i get the error.

Well, I guess you can check if the power source exists with findfirstchild or whatever works

how the wiring logic works is there is a output bool-value in the power source in this case a switch. and a object value in the light block and every .5 seconds its changing the light depending on if the output value is true or false. Its just that when the switch is deleted then it no longer exists so it errors.

also findfirstchild wouldn’t work because its a placement game with many of the same blocks

Hello, so you would like to get rid of the error that appears once an instance is deleted? In this case, you can handle it with pcall.

1 Like

k thxxxxxxxxxxxxxxxxxxxxxxxxxxx

local success,error = pcall(function()
local part = ObjectValue.Value 
end)

if success then
—run object value exists code
end
1 Like

still producing the same error

It cant produce errors in pcall😑

well its still erroring. not the pcall the
image

Can you show me error, so I can tell what is wrong?

as I’ve said it’s just a error because the switch/output doesn’t exist anymore