InstanceState<T>
A value that is kept separately for each instance and tells you when it changes, which you create with state.create_per_instance.
Events
You listen to these with :connect, which the Event page covers.
Gives a copy of one instance's value, which still works for 5 seconds after it is destroyed.
example
print(health:get(door))
Use it forchecking how much health a crate has left before deciding whether it breaks.
Changes one instance's value, and is an error once that instance is destroyed.
example
health:set(door, 100)
Use it formarking a checkpoint as reached, or setting whether a door is locked.
instanceThe instance.
valueThe new value.
InstanceState:update
method#Hands your function one instance's value, and saves whatever it gives back.
example
health:update(door, function(value) return value - 10 end)
Use it forchanging a tower's upgrade level when its data is stored together as a table.
instanceThe instance.
updateGets the value and returns the new one.
InstanceState:increment
method#Adds to one instance's number value, or takes away, and gives back the new value.
example
health:increment(door, -10)
Use it fortaking a bit of health off a wall each time a player hits it.
instanceThe instance.
amountoptionalHow much to add, 1 by default. A negative amount takes away.