Make loop include

The main problem is That if you open another door while they entity is rushing into you direction, then it will not go to the next room you open and you are just safe in it

2 Likes

I hope you do now better understand my problem do you?

1 Like

I don’t know how the developers of the original doors game mated. But it is really fascinating because I don’t know how to do it

1 Like

You want the entity to go through every doors the player has ran into?

Yes and also into every future one

1 Like

Asked long as the loop is running

You can check out this video that opens doors in its way. I’m sure you could implement your own animation or smth on that door.

I don’t think that you still understand the problem

My problem is not that it does not open Opening doors my problem is that I want the entity to go through every room That is opened after the entity started running

Since I am using twin service for it it is Really hard to do it

I apologize for that, I’m feeling very sleepy today. So you want the entity to go through opened doors?

Yes exactly and I wanted to go through every door that has opened After the loop already started

Have you tried it with while-statements?

The loop looks like this
For a,b in ipairs(rooms:getchildren())
Do …go to room… end

The problem is that while the loop has already started… The player is running into new rooms that get generated into the folder called “rooms”.
The loop does not include the new added rooms.
This means that the player is safe by just stepping one more room forward

I’m having this problem for more than three years already and I cannot solve it.

I do not want to restart a loop

I do not want the entity to go block it through the rooms

I want smooth movement for the edity

The Entity is using twin service

Please help

We can assume this process is a queue that fills each time an instance is added and runs code for each cycle until it empties itself:

local queue: {Instance} = {}

function addToQueue(child: Instance) table.insert(queue, child) end

folder.ChildAdded:Connect(addToQueue)
for _, child in pairs(folder:GetChildren()) do 
	addToQueue(child)
end

while true do
	local element = queue[1]
	--if you want to keep checking after the queue is empty, remove the line below
	if element == nil then break end
	table.remove(queue, 1)
	print(element)
	task.wait(1)
end

Also if you just want to run code for every object, do the following:

function childAdded(child: Instance)
	--your code here
	print(child) --example
end

folder.ChildAdded:Connect(childAdded)
for _, child in pairs(folder:GetChildren()) do
	childAdded(child)
end

In general, what you’re looking for is event-based because you want it to be dynamic.

2 Likes

Thank you so much, but how am I supposed to implement that into the existing code

I am simply twinning The entity threw an area of parts

It’s this thing restarting a loop every time something gets added?