Ok so I'm trying to make a cell service with cell towers so when a player is close or far it will act like a cellphone but I'm having troubles finding more then one brick. How can I have this find more then one brick?
local part = game.Workspace.Cell:GetChildern() -- I want this to find everything in the Model Cell but don't know how to add it to the purtion of the script below...
while true do
for i,v in pairs(game.Players:GetChildren()) do
if (v.Character.Torso.Position - part.Position).magnitude <= 50 then
v.PlayerGui.ScreenGui.TextLabel.Text = "-----"
elseif (v.Character.Torso.Position - part.Position).magnitude <= 100 then
v.PlayerGui.ScreenGui.TextLabel.Text = "----"
elseif (v.Character.Torso.Position - part.Position).magnitude <= 150 then
v.PlayerGui.ScreenGui.TextLabel.Text = "---"
elseif (v.Character.Torso.Position - part.Position).magnitude <= 200 then
v.PlayerGui.ScreenGui.TextLabel.Text = "--"
elseif (v.Character.Torso.Position - part.Position).magnitude <= 250 then
v.PlayerGui.ScreenGui.TextLabel.Text = "-"
elseif (v.Character.Torso.Position - part.Position).magnitude <= 300 then
v.PlayerGui.ScreenGui.TextLabel.Text = "No Service"
end
end
wait()
end

10 comments
Tried I got this error now attempt to compare two userdata values on line 20...
which on here is line 21 plr was not defined...
Edited
Why use a table when you could just keep track of a "bestMagnitude" value? No need to sort a table of values that you aren't going to use. Further, what's the point of adding "and val > 50" on line 25? "val > 50" is guaranteed by line 23's conditional not being true. Also, any particular reason you're using .CFrame.p instead of .Position ? Finally, I'd recommend replacing line 33 with "else"
This way I just though it would be easier, since the table.sort function exists. Idk, doesn't really matter. I'm using CFrame.p since I normally deal with CFrames, rather than Vectors - Just a habbit. That last suggestion was actually good. Why critisize my code if it works effectively and for the most part efficiently, though?
There's no point in going for a slightly more efficient method when the readability is awful. People can understand my code better than yours and the changes you made aren't really worth changing. A few millaseconds worth of increased performance rate isn't worth making the code ugly.
It just seems like unnecessary processing. Sorry, I suppose I'm "prematurely optimizing".
What part of my code is so ugly? (If you just mean line 18, I can agree it's harder to understand (though potentially more powerful))
'ugly' is a strong word but yes.. 18 is harder to read / understand. But like I said, trading in readability for miniscule performance rate enhancement isn't worth it.. if you're giving an answer to the public.
Thx Goulstem!