How to handle hundreds of items that need user input?

I am working on a little game where you can build with blocks (similar to a famous mining and crafting game)

Since I have some items that will need user input, such as Doors, Levers, Furnaces, etc…
I am wondering what is the best way to do this.

My initial idea, is to have the BlockManager, detect if say, the block is a Door, then send a message to a DoorManager script, and it finds the door’s proximity prompt, and creates an event listener for that specific door. However, I’m not sure how to handle the tweening of the door opening or the storage of the door’s state.

I could have a table in the DoorManager script that keeps track of data for each door, and in that data, had a state for open or close, so I know the state of the door. But would a table with data entries be better than, say, adding an ‘attribute’ to the door object, that can keep track of its open or closed state?

For actual animating of the door, I would use tween service, but then again… Do I create a new tween for each door (there could be hundreds of them) or should I only create a tween for when a door is used, then destroy it? How would this be done if you want the door to open or close even if it hasn’t finished opening or closing (such as deleting tweens when they are in operation) Or… should I create my own Debris library, so that when a tween is created, it is put in the Debris for 5 seconds, and only if it is used recently will that 5 seconds be reset to 5 seconds again.

Idk… I guess I’m just looking for any ideas or best practices with this sort of thing.

Thanks.

try to create your own TweenService:

local Module = {}
local TweenService = game:GetService('TweenService')
local RunService = game:GetService('RunService')

function Module:Tween(Model: Model, Goal: CFrame, EasingStyle: Enum.EasingStyle, EasingDirection: Enum.EasingDirection, duration: number): ()
      local Time = duration/(1/.05)
      local actualCF = Model:GetPivot()
      for alpha = 0, 1, .05 do
            local t = TweenService:GetValue(alpha, EasingStyle, EasingDirection)
            Model:PivotTo(actualCF:Lerp(Goal, t))
      end
end

return Module
1 Like

Hello :), if you want to handle many things that need to do the same thing, the best way to do that is with CollectionService.
How it work is basically it detects whenever a tag is added to an object, and then you can use all of the objects with that kind of tag. Then you could check whenever the ProximityPrompt (if you are using them) in the door is triggered. If so, the tween Plays. An example:

--SERVICES--
local CollectionService = game["CollectionService"]
local TweenService = game["TweenService"]

local Collection = {} -- this is to store our objects

local function TweenDoor() -- Function that gets called if the proximity prompt is triggered
      -- PUT YOUR TWEEN HERE.
end

local Function ObjectAdded(Object)
local ProximityPrompt = Object:FindFirstChildWhichIsA("ProximityPrompt")
   if Object:IsA("Model") and ProximityPrompt then -- if the object is a model (i assume a door would be a model but you can change it anyways) and there is a proximityprompt, then:
         Collection[Object] = ProximityPrompt.Triggered:Connect(TweenDoor) -- gets stored, and whenever the pxPrompt is triggered it calls the TweenDoor Function.
   end
 end

 CollectionService:GetInstanceAddedSignal("YOURTAGHERE"):Connect(ObjectAdded) -- This function checks whenever a object with a type of tag is added.

As for the tags you can add them manually from the Properties of the model / part ecc…
Let me know :slight_smile:

1 Like

Wow, these are some really nice ideas, thanks!

1 Like