Hi guys, i try to loop players in radius of my boss i have try to make this script but it’s not work:
local heal = script.Parent.Ennemy
range = 100
Players = game:GetService("Players")
for i, player in pairs(Players:GetPlayers()) do
while wait(1) do
if heal.Health <= 2550 then
local fox = script.Parent.PrimaryPart.Position
local dist = (fox - player.Character.PrimaryPart.Position).magnitude
if dist <= range then
print(player.Name)
end
end
end
end
Encompass the loop inside a spawn function so each player receives a looped thread of their own. Either that or run the for loop for every cycle of the while loop.
local heal = script.Parent.Ennemy
range = 100
Players = game:GetService("Players")
while true do
for i, player in pairs(Players:GetPlayers()) do
if heal.Health <= 2550 then
local fox = script.Parent.PrimaryPart.Position
local dist = (fox - player.Character.PrimaryPart.Position).magnitude
if dist <= range then
print(player.Name)
end
end
end
wait(1)
end