#How to get Players that in the Zone

1 messages · Page 1 of 1 (latest)

zealous patio
#

I have a 20 zone that i calculate by magnitude. And i want to get all players that are in zone and change their BoolValue that i give them in the start of the game. The problem is that i did it and its working but i have a freez when i enter the zone

#
local module = {}


function module.new()
    local self = {}

    local plrChange = {}
    -- Функция запуска зоны
    function self.StartZone(zonePart, radius)
        while true do
            for _, plr in pairs(game.Players:GetPlayers()) do
                local chr = plr.Character or plr.CharacterAdded:Wait()
                local hrp = chr:FindFirstChild('HumanoidRootPart')
                local change = plr:FindFirstChild('Change')
                
                if plrChange[plr] == nil then
                    plrChange[plr] = {plrChange = nil}
                end
                
                local distance = (plr.Character.HumanoidRootPart.Position - zonePart.Position).Magnitude

                if distance <= radius then
                    if plrChange[plr].Change == false then return end
                    print('Plr in Zone!')
                    change.Value = false
                    plrChange[plr].plrChange = false
                elseif distance > radius then
                    if plrChange[plr].Change == true then return end
                    change.Value = true
                    plrChange[plr].plrChange = true
                end
            end
            task.wait(0.3)
        end

    end


    return self
end


return module
#

that my code

#

so like i said its workin but have a big abt 3 minutes freez

#

and if just comma the change.Value then its not lagging but if i stand for like 5 minutes in a zone fps is getting very low

#

pls help

#

oh i found that if i change my Change Value in game not by code it lagging too

tepid treeBOT
#

studio** You are now Level 3! **studio

past fable
#

picking my nose rn

zealous patio
#

thats weird

zealous patio
zealous patio
#

i fixed

#

finally