Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to change the object value's value to nil when object is destroyed?

I'm having a problem where an object value with a value equaled to the player's character doesn't recognize it when the player dies, therefore the character is destroyed. Even though the object doesn't exist, if I access the object through the object value instance it returns as if the character model exists. How can I fix this such that the object value's value become nil when the object doesn't exist any more.

1 answer

Easy change it to nil

ObjectValue.Value = nil

or detect when object is destroyed do this

local Value = ObjectValue.Value
local partParent = Value.Parent
partParent.ChildRemoved:Connect(function(item)
	if item == Value then
		ObjectValue.Value = nil
	end
end)

1 comment

0

Welp you beat me to it

This discussion is preserved as it was. New answers, comments, and votes are closed.