Ad
Log in to vote
0

Why wont GetChildren Get ALL the Children?

Asked by
joeldes 79
9 months ago
Edited by BlueTaslem 9 months ago

Basically my issue is that the GetChildren function seems to only be grabbing just a few of the parts in the folder.

print("Intalizing Eat Script")

local ReplicatedStorge = game:GetService("ReplicatedStorage")
local eatEvent = game.ReplicatedStorage.EatEvent

local player = game.Players.LocalPlayer
local character = player.Character

local stars = workspace.Food.Stars

local running = true
local ticks = 1

if character:findFirstChild("Humanoid") then
    local playerLocation = character.HumanoidRootPart.Position

    -- Main Loop        
    while running do
        -- Stars Variable
        local stars = workspace.Food.Stars:GetChildren()

        -- Loop Through Parts
        for i,Part in pairs(stars) do
            local magnitude = (playerLocation - Part.Position).magnitude

            if magnitude <= 300 then
                print(Part.Name, " - " ,magnitude)
                eatEvent:FireServer(Part)

            end

        end
        wait(1/ticks)
    end

    print("End Loop")

end
2
Why did you post a pastebin rather than using the site's Lua converter? PreciseLogic 251 — 9mo
0
GetChildren() will return an array of ALL of the parent's children. I do not think it's the method that has the problem, rather how you're using it. My guess is some of the children do not follow your conditional. You can always print() to have a 'visual' of all the children. PreciseLogic 251 — 9mo
0
Edited to replace pastebin link with code BlueTaslem 16813 — 9mo

Answer this question