ObjectValue simply put is a way to store a value, but as an object. Similar to how all value instances hold a specific value respective to their data types.
For instance, if I needed to save a character, but not by their name, I’d use an ObjectValue and set that value equal to their character. Now, that ObjectValue stores that character only, even if there no name variances.
If you have more questions, I’d recommend you go on here to look more:
But why would you create an objectvalue over just directly referencing the character to begin with? My problem is that it seems like a redundant feature. If I assign a character to the variable “c” then have I not just stored a reference to the character with the variable? How and why would it be better to use an ObjectValue over a plain variable reference?
My main question is asking what the purpose or use case for ObjectValue is, not what it is itself. The question states that I’ve read the reference, I’m just having trouble understanding WHY you would need to use such a thing.
I use ObjectValues all the time, really. Mainly, for NPC’s and to log someone’s last attacker, so that way if they’re an NPC, or character alike, I log their character instead of having to make an exception for NPC’s and that’d be super messy.
What I mean is like, so once that last attacker is stored in that object value, if that player dies without being touched by anyone else (i.e resetting, or dying from other means), that we can give the logged person a kill based on the last logged person
I am a little late lol, but since this is still open I may as well answer.
You might already have learnt this but I can still answer you!
Object values are values that you can store an instance to make things easier.
I’d say the best use of ObjectValues is using it as a global “variable”. This can help you use sorts of code in seperate scripts!
You can check to see if the value has changed so you can fire something, like doing so:
local value = script.Parent.ObjectValue
value.Changed:Connect(function()
print("Value has changed")
end)