#Why does my for loop only detect a single person?

1 messages · Page 1 of 1 (latest)

native knoll
#

How can i make sure it detects multiple at once?

#
for i, player in ipairs(Players:GetPlayers()) do
        local Character = player.Character or player.CharacterAdded:Wait()
        --if not Character then return nil end
        local Values = Character:FindFirstChild("Values")

        if Values:FindFirstChild("Killer") then
            Killerplayer = player
            --print("Found killer! Killer: ".. player.Name)
            --elseif Values:FindFirstChild("Survivor") then
        end

        if Killerplayer == nil then break end
        if Killerplayer.Parent ~= Players then break end

        local KillerChar = Killerplayer.Character
        local khrp = KillerChar.PrimaryPart or KillerChar.HumanoidRootPart

        local hrp = Character.PrimaryPart or Character.HumanoidRootPart

        local distance = (khrp.Position - hrp.Position)
        local distanceinstuds = distance.Magnitude
        
        task.delay(0, function()
            print(distanceinstuds)
        end)
        if distanceinstuds == 0 then    
        elseif distanceinstuds < MaximumChase then
            print("in range")
            hallucinations:FireClient(player, distanceinstuds)
            Event:FireClient(player, distanceinstuds)
            Event:FireClient(Killerplayer, distanceinstuds)
            break
        elseif distanceinstuds > MaximumChase then
            print("more than 60 studs")
            EventEnd:FireClient(player)
            EventEnd:FireClient(Killerplayer)
            return
        end
        
        
    end``` this is my current function to detect players in a server
#

and with it i made a chase theme player based on distance, however it only works if the first player who has joined the server become killer instead of all

#

ill post a video context

wicked stratus
native knoll
#

these?

        if Killerplayer == nil then break end
        if Killerplayer.Parent ~= Players then break end
#

the first line is a variable and the second is checking if the player if killer, is under the players parent incase they disconnect

still sky
#

if at any point the break keyword is hit, the loop will end