I'm having an issue using ObjectValue(s) because they wont update their value when their object gets deleted. How can I get their value to update if their object gets destroyed?
✓ ANSWER ACCEPTED
Can you get ObjectValue(s) to automatically update?
1 answer
✓ Accepted answer
Simple, just make it so when the part's parent changes, it checks if it's parent is nil or not. If it is, then update the value. Here's an example:
local Part = Instance.new("Part") -- The object
-- Create & Assign the value
local ObjValue = Instance.new("ObjectValue")
ObjValue.Value = Part
-- Connect a function that fires when the part is changed
Part.Changed:connect(function(property)
-- If the property changed is "Parent", and the part's parent is now nil, then...
if property == "Parent" and Part.Parent == nil then
-- Update the value to nil.
ObjValue.Value = nil
-- End the if statement
end
-- End the event
end)
Hope that helped, let me know if you have any questions.
This discussion is preserved as it was. New answers, comments, and votes are closed.
