Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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.

01local Players = game:GetService("Players"):GetPlayers()
02local seeker = script.Parent
03local pickedPlayer
04game.Workspace.Active.Changed:Connect(function()
05    if game.Workspace.Active.Value == true then
06        wait(10)
07    while game.Workspace.Active.Value == true do
08            for _, player2 in ipairs(game.Players:GetPlayers()) do
09        if player2.Character.Hiding.Value ~= true then
10                seeker.Torso.CFrame = player2.Character.Torso.CFrame
11                wait(2)
12                if player2.Character.Hiding.Value ~= true then
13                    player2.Character.Humanoid.Health -= 100000000000
14                end
15        end
16        end
17        end
18        end
19end)
0
What exactly do you mean with lag? every wait() causes the whole script to do nothing in that time. For ececuting too many times: If you dont set the acitve value to false again it is going to continue forever as you have a while loop. xXMadonXx 190 — 2y
0
wow there is a lot of spelling mistakes in my comment xD xXMadonXx 190 — 2y
0
The scripts exhausts its allowed execution time. I cant immediately disabled active as that's the value keeping the monster active. Uniplier 83 — 2y
0
did you just... "player2.Character.Humanoid.Health -= 100000000000" A_Mp5 222 — 2y

Answer this question