Game lags bad if all players are hiding when monster is released?
Asked by
2 years ago Edited 2 years ago
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.
01 | local Players = game:GetService( "Players" ):GetPlayers() |
02 | local seeker = script.Parent |
04 | game.Workspace.Active.Changed:Connect( function () |
05 | if game.Workspace.Active.Value = = true then |
07 | while game.Workspace.Active.Value = = true do |
08 | for _, player 2 in ipairs (game.Players:GetPlayers()) do |
09 | if player 2. Character.Hiding.Value ~ = true then |
10 | seeker.Torso.CFrame = player 2. Character.Torso.CFrame |
12 | if player 2. Character.Hiding.Value ~ = true then |
13 | player 2. Character.Humanoid.Health - = 100000000000 |