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

Leaderboard Stats & Finding?

Asked by 10 years ago

I have been trying to use the

local players = game.Players:getChildren()

in my function , this is what i go.

if players == 1 then
    print("Starting Minigame.")
    print("Enough Players!")
    m = Instnce.new("Message", game.Workspace)
    m.Text = "Starting Minigame!"
    wait(5)
    m:Destroy()
end

I get no errors in the output, but nothing happens. I've tried the NumPlayers variable but it does nothing.... Anyone mind pointing me in the right direction?

====================== I've also been trying to create a leaderboard stats that once the wait() is up, it gives them tools?

Leaderboard:

function CreateStats(name, parent, value)
    var = Instance.new("IntValue")
    var.Name = name
    var.Parent = parent
    var.Value = value
end

function Entered(newplayer)
if newplayer:findFirstChild("leaderstats") == nil then
CreateStats("leaderstats", newplayer, 0)
CreateStats("Level", newplayer.leaderstats, 0)

end
end
game.Players.PlayerAdded:connect(Entered)

p = game.Players:GetChildren()
for i = 1, #p do
Entered(p[i])
end

The Timer:

if game.Players.LocalPlayer.leaderstats.Level.Value == 0 then
    wait(2)
    game.Players.LocalPlayer.leaderstats.Level = game.Players.LocalPlayer.leaderstats.Level.Value +1
    wait(2)
    m = Instance.new("Message", game.Workspace)
    m.Text = "You've recieved build tools!"
    wait(2)
    m:Destroy()
elseif game.Players.LocalPlayer.leaderstats.Level.Value == 1 then
    --Inserting random tools etc--
end

Thanks in advanced.

4
Try game.Players.NumPlayers >=1 and also you mispelled Instance for the first message. systematicaddict 295 — 10y
2
It's :GetChildren() not :getChildren() Kozero 120 — 10y
2
It doesn't matter if you use 'getChildren' or 'GetChildren'. getChildren was original name of that method anyway, so it won't go anywhere. ZarsBranchkin 885 — 10y
0
getChildren and children are both references to the current GetChildren. They're deprecated, but only because you should aim to use the most up to date naming scheme. adark 5487 — 10y

1 answer

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
10 years ago

In your second bit of code, you made a simple mistake:

if players == 1 then

players will never be equal to the integer 1, because players is a reference to a Table. You have to use the size-of operator (a hash: #) to perform this check properly. Another thing to note is that this will only run if there is exactly one player playing, and I assume you want it to be one or more, so the equals has to be changed to greater than or equal.

The size-of operator for Lua Tables only works properly if the table has only integer indices that start at 1 and go up by 1 for every value in the table.

(This is basically the default, this table:

{element1, 21, "turbulance", sasquatch.Element.Value}

follows that pattern. Note how I let the elements be given indexes automatically.)

Any ROBLOX method that return a table, e.g. GetChildren, will have the table be in this format.

if #players >= 1 then

Since you are using a snapshot of Players, which is a good practice in case somebody joins in the middle of a game, I would avoid using the NumPlayers property in this case.

0
Thanks! So # Will check instead of putting an exact interger? TwoSlhue 5 — 10y
Ad

Answer this question