Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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

Log in to vote
1
Answered by
OnaKat 444 Moderation Voter
5 years ago

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)
0
Welp you beat me to it Joshument 110 — 5y
Ad

Answer this question