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

How to check for a number of objects?

Asked by 8 years ago

I am making a game management system kind of like RDS and I need help figuring out how to find the number of children in an object. Here is my script so far:

local playerNum = game.Players.NumPlayers

while true do
    wait(1)
    for _,p in pairs(game.Players:GetPlayers()) do
        if not script.Parent:FindFirstChild(p.Name) or p.Name == game.Players.LocalPlayer.Name then
            local button = Instance.new('TextButton')
            button.Parent = script.Parent
            button.Name = p.Name
            button.Position = -- This is where I need to figure out the number of objects before continuing
        end
    end
end

In StarterGui, this is what my explorer window and view looks like:

Explorer window: http://i.imgur.com/352MOhc.png

Player view: http://i.imgur.com/t2aUisg.png

1 answer

Log in to vote
0
Answered by
NotSoNorm 777 Moderation Voter
8 years ago

We simply use #! (not hash tag ya knob, number)
So say, for example, we do local parts = #game.Workspace:GetChildren() that would set a variable to the number of parts in workspace.

I don't really know where I'd put the line in your script so I'm just going to give you that.

Ad

Answer this question