I’m making a fangame of the game REx:R but i’m having trouble making the game optimized
Currently all ores postions are stored in a folder as values but i’m wondering how to make them into a table instead so it dosent need to make thousands of objects for no reason
the current code
local val = Instance.new("Vector3Value")
val.Value = newPos
val.Parent = game.ServerStorage.Generated
You can use :GetChildren() to get all the positions stored in the folder. Afterwards, you can use table.insert(table here, value here) to insert the position into the table.
the base layer in serverstorage is just for when the mine resets, and the ores folder is for all the ores that exist, and generated puts vector3values in it and the script checks all of the values to check if it was previously generated, but it starts getting laggy after a bit of mining since it has to check through thousands of values to find 1
You can do table.find(table, value) to find its position
I’m not a great coder but you can use tables like this for it,
local UngeneratedValues = {} -- for all new values, not mined ones
local GeneratedValues = {} -- for all currently spawned ores
local val = Instance.new("Vector3Value")
val.Value = newPos
val.Parent = game.ServerStorage.Generated
table.insert(UngeneratedValues, val) -- when its made it'll start ungenerated in terms of tables.
for i, generated in pairs(UngeneratedValues:GetChildren()) do
if generated.Value == "newPos" then
previouslyGenerated = true -- idk what this is so i just left it in
table.remove(UnGenerated, generated) -- removing from ungenerated as well, Deleting it so you dont have thousands of unnecessary values. Create more as needed.
table.insert(Generated, generated) -- adding to generated because im assuming newpos will be replaced as this value is *new*
else -- if it DOESNT have its value as "newPos" its put into the "Generated" table, for ores that are generated.
table.insert(Generated, generated)
table.remove(UnGenerated, generated)
end
end
and then if the ore were to be mined you can do table.remove(table, item) or just delete its value.
It’s messy because Im struggling to figure out why youre doing what youre doing
but this is somewhat of how tables work, probably a better way but im going off of what you have so…
having 2 tables is a bad idea as if you read the code it already wont work but this is more of an example