Yeah, actually attributes would be best in this situation. You could group rocks with the same MaxHealth together into a folder/model giving the model a MaxHealth attribute that all of its children would possess, then each rock would have a health attribute showing their indiviual health. That’s assuming MaxHealth is consistent and the most important property of the rocks.
I think it highly depends on the mining mechanics. If its desired that each rock has its own health property and the rock preserve that health forever, then no.
If a group of rocks share the same attribute which belongs to a parent model, then its not possible to have individual health per rock.
If the idea is just having a health limit that will go back to full if the player stop mining it, (idk like minecraft, if you stop mining the block returns to its full health) then yes. Having a base health that will be checked and reduced each hit and when it reach the max limit it will break, would be efficient to have “groups” of rocks.
In the case thats the desired behavior, and there are multiple types of rocks, and its health goes back to full if player stop the mining. A folder with attributes or even a table with folder’s name (rock type) to know the max rock health in order to break it
I didn’t see this reply of yours, but basically what I wrote here was what you had already suggested but assuming that an ore instance has a constant max health shared with other ores of the same kind, therefore we should group similar ores into folders. If you have diamond ore the max health may be 100 while gold’s max health is 60. In this case, we can put similar ores and rocks into folders based off of how long it would take each to be mined(Max Health). For example, cobblestone ore models would go into a folder called cobblestones, and the folder would have an attribute called MaxHealth set to 20. This way we don’t need to have a MaxHealth attribute for every stone, only a Health attribute, as Health will be the only property different for any ore at any given moment.
Tables within a module script would work great as well but I prefer using properties, attributes, and BaseValues for systems in scenarios where they be just as modular and performant.
But as you said the OP does need to clarify further how the system works because we’re currently working off of assumptions.
Add an attribute to all different rock types called health. Folder these rocks under a folder called “AllTypesOfRocks”. Every time you make a new rock generate on the map, clone a rock under the folder, then parent to somewhere else. Attributes will carry on when cloned. To remove health, you can use SetAttribute. When the value is less than 0, destroy the rock.
Create a Rock Template: In Roblox Studio, create a template for your rocks. This can be a Model containing a Part representing the rock and other necessary parts such as a HealthBar.
Add Properties: Add NumberValue instances to your Rock template to store the health and max health values.
Scripting: Write scripts to handle the logic of your rocks. You can use the Instance’s properties to retrieve and update health values.
local rock = script.Parent -- Assuming the script is a child of the rock object
local healthValue = rock:WaitForChild("Health")
local maxHealthValue = rock:WaitForChild("MaxHealth")
-- Function to damage the rock
local function damageRock(amount)
local currentHealth = healthValue.Value
local newHealth = currentHealth - amount
if newHealth <= 0 then
-- Rock destroyed
rock:Destroy()
else
-- Update health value
healthValue.Value = newHealth
end
end
-- Example usage
local damageAmount = 20
damageRock(damageAmount)
rock represents the rock object.
healthValue and maxHealthValue are NumberValue instances storing the health and max health values, respectively.
The damageRock function decreases the rock’s health by a specified amount and destroys the rock if its health reaches zero.
This approach allows you to manage the health and max health of rocks efficiently within the Roblox environment, similar to what you might have seen in games like Refinery Caves and Oaklands.