Ad
Log in to vote
1

Game lags bad if all players are hiding when monster is released?

Asked by 20 days ago
Edited 20 days 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.

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)
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 — 20d
0
wow there is a lot of spelling mistakes in my comment xD xXMadonXx 190 — 20d
0
The scripts exhausts its allowed execution time. I cant immediately disabled active as that's the value keeping the monster active. Uniplier 83 — 18d
0
did you just... "player2.Character.Humanoid.Health -= 100000000000" A_Mp5 222 — 18d

Answer this question