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

My game crashes when I start the game I dont know why please help?

Asked by 4 years ago
Edited 4 years ago
function gethumanoids()
    local humanoidpos = {}

    for i,x in pairs(workspace.NPCS.Outriders:GetChildren()) do
        if x:FindFirstChild("Humanoid") and x~= script.Parent then
            table.insert(humanoidpos,(script.Parent.HumanoidRootPart.Position - x.HumanoidRootPart.Position).magnitude)

        end
    end

    table.sort(humanoidpos)

    for i,x in pairs(humanoidpos) do
        if x ~= 1 then
            table.remove(humanoidpos,i)
        end
    end

    for i,x in pairs(workspace.NPCS.Outriders:GetChildren()) do
        if x:FindFirstChild("Humanoid") and x ~= script.Parent then
            if (script.Parent.HumanoidRootPart.Position - x.HumanoidRootPart.Position).magnitude == humanoidpos[1] then
                return x
            end
        end
    end
end
while wait() do
    local target = gethumanoids()
    script.Parent.Humanoid:MoveTo(target.HumanoidRootPart.Position)
end

I don't know why my game crashs like 2 seconds after starting

Its a script for a friendly NPC fighting nearest enemy NPCS

0
It's probably because you're iterating through large tables so fast. What exactly is this script supposed to do? I can re-write it for you. Internal_1 344 — 4y
0
its a script to make a npc follow enemy npcs and kill them Boindoin -7 — 4y
0
I just realized that everytime it attacks it freezed Boindoin -7 — 4y
0
Its when it reaches the target it freezes Boindoin -7 — 4y
0
i just realized that the problem was a different script i had a healing script it activates everytime its health changes but it has no wait time so it goes on forever lol Boindoin -7 — 4y

Answer this question