Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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.

0
Coroutines, coroutines, all da coroutines are not here. hiimgoodpack 2009 — 6y
0
How do I get the coroutines to keep going though? UnleashedGamers 257 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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

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? UnleashedGamers 257 — 6y
Ad

Answer this question