I'm working on a little game where every 60 seconds there's a chance a monster will wake up and teleport to players, instakilling them. The player can avoid this by getting into a locker before he kills them. The problem is, whenever every player is hiding, the loop I use to get all the players executes too many times and lags. Is there a way to fix this?
Below is the code for the monster.
local Players = game:GetService("Players"):GetPlayers() local seeker = script.Parent local pickedPlayer game.Workspace.Active.Changed:Connect(function() if game.Workspace.Active.Value == true then wait(10) while game.Workspace.Active.Value == true do for _, player2 in ipairs(game.Players:GetPlayers()) do if player2.Character.Hiding.Value ~= true then seeker.Torso.CFrame = player2.Character.Torso.CFrame wait(2) if player2.Character.Hiding.Value ~= true then player2.Character.Humanoid.Health -= 100000000000 end end end end end end)