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

Loop function randomly quits after 39 lines but doesn't give an error?

Asked by 5 years ago
Edited 5 years ago

Hellur, so I have a simple for loop inside of a local function that should run but does not. Either something is really wrong or I just broke it some way. The output does not give any error, the function just does not run past line 39.

Server script: Please ignore the prints. I know there is like 3 types I used.

local Scan = {'G17'}
local Status = script.Parent.Parent.Parent.Parent.Status
local Label = script:WaitForChild("Example")
local Scanner = script.Parent.Parent.Parent.Parent:GetChildren()
local Detector = script.Parent.Parent.Parent.Parent.Regoin
function CallRegion(Area)
    print(Area)
    local upVal1 = Area.Position - (Area.Size/2)
    local upVal2 = Area.Position + (Area.Size/2)
    print(upVal1, upVal2)
    return Region3.new(upVal1, upVal2)
end
local function LocatePlayers(Area)
    print 'Called'
    for _,v in pairs(Status.Text.Frame:GetChildren()) do
        if v.Name == "Player" then
            game:GetService("Debris"):AddItem(v, .1)
        end
    end
    print'20'
    local Region = CallRegion(Area)
    local GetParts = workspace:FindPartsInRegion3(Region, nil, math.huge)
    local Players = {}
    print'24'
    for _,v in pairs(GetParts) do
        local Player = game.Players:GetPlayerFromCharacter(v.Parent)
        if Player then
            for i,_ in pairs(Players) do
                if not Players[i].Name == Player.Name then
                    table.insert(Players, Player)
                    print 'Ye boiiiiiiiszzxxx.'
                    for q,n in pairs(Players) do
                        print(Players[q])
                    end
                end
            end
        end
    end
    print'37'
    for i,_ in pairs(Players) do
        print'Checking...'
        for _,tools in pairs(Scan) do
            if Players[i].Backpack:FindFirstChild(tools) then
                print 'Oof. I got that unarmed thing wrong.'
                --[[local Clone = Label:Clone()
                local Name = string.upper(v.Name)
                Clone.Text = Name.." - [ARMED]"
                Clone.TextColor = Color3.fromRGB(250, 36, 21)
                Clone.Name = "Player"
                Clone.Parent = Status.Text.Frame]]
            else
                --[[local Clone = Label:Clone()
                local Name = string.upper(v.Name)
                Clone.Text = Name.." - [UNARMED]"
                Clone.Name = "Player"
                Clone.Parent = Status.Text.Frame]]
                print 'Someone is armed!'
            end
        end
    end
    print'61'
    return Players
end

script.Parent.MouseClick:Connect(function(Player)
    if Player.TeamColor ~= BrickColor.new("Dark stone grey") then
        return
    else
        LocatePlayers(Detector)
    end
end)
0
61 never prints? If the pairs on line 40 never runs its likely because the Players table is empty, try printing it. DinozCreates 1070 — 5y
0
61 does print. The table cannot be empty as if you had looked at the script, it does print everything in the table on line 32. So there are objects in the table but this doesn't function the way it should. namespace25 594 — 5y
0
It does print checking... tho. So they're not empty. namespace25 594 — 5y
2
Maybe dont give the person attitude whos trying to help you out. Best of luck. DinozCreates 1070 — 5y
View all comments (4 more)
0
Exactly, Dinoz. But anyways why does it say "Tools in pairs.." but there's no 'Tools' Variable? UltraUnitMode 419 — 5y
0
There is no variable requirement for a loop except what you're looping through. For example: for i,v in pairs() used "i" and "v" without a set variable. namespace25 594 — 5y
0
Dinzo, sorry if it seemed that way. That is not how I intended it to read. namespace25 594 — 5y
2
He wasn't giving an attitude, he was stating his opinion. greatneil80 2647 — 5y

Answer this question