Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I make this check multiple blocks at the same time?

Currently this only checks one block and doesn't check the rest of them, how can I fix that?

for i,v in pairs(model:GetChildren()) do
	if v:IsA("Part") then
		while wait(1) do
			if player:DistanceFromCharacter(v.Position) <= 20 then
				print('near');
			else
				print('not near');
			end
		end
	end
end-

It only prints 'near' when you get near only one block in the model, and yes the bricks are spread out past 20.

2 comments

0

Coroutines, coroutines, all da coroutines are not here.

0

How do I get the coroutines to keep going though?

1 answer

The problem is that a while loop like the one you have repeats infinitely - it never stops, so it never gets past the first part.

print("Hello")

while wait() do

end

print("world!") -->> this doesn't print because the loop is infinite

The way I think you'd want it to run would be:

while wait(1) do
	for i,v in pairs (model:GetChildren()) do
		-- code
	end
end

Hope I helped!

~TDP

1 comment

0

It now recongizes them all, but still only works when your near one of them. I currently have 2 bricks placed far apart and when you go near the first one it works, but when you near the second one it doesn't work. I believe this is occuring because its check if its near both bricks at the same time as it conts to print both "near" and "unnear" once I get close to that brick. Ideas?

This discussion is preserved as it was. New answers, comments, and votes are closed.