So, I have a script that detects players nearby who have less than 100 hp.
I know what the problem is, it’s just that if there are no players nearby, then the table doesn’t get players in any way and I’ve already tried something and it didn’t help. I need an idea how to run the script again if the players were not detected and not get an error that will completely break the script.
local tablet = {}
for i,v in pairs(workspace:GetDescendants()) do
if v.Parent:FindFirstChild("Humanoid") and v.Parent:IsA("Model") and v.Parent:FindFirstChild("Humanoid").Health ~= 100 then
if table.find(tablet, v.Parent) then continue end
if (v.Parent.PrimaryPart.Position - player.Character.PrimaryPart.Position).Magnitude <= 30 then
table.insert(tablet, v.Parent)
end
end
end
local random = math.random(1,#tablet)
local randomplayer = tablet[random]