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

How do I check if ALL PLAYERS in game have a tool?

Asked by 10 years ago

This is my current script, and for some reason it is not working.

function TimerEnd() 
    wait(30)
    Check = game.Players:GetChildren()
    for i=1,#Check do
        BKP = Check[i].Backpack:GetChildren() ------Indexes the backpack of the player[i]'s...
        for i=1,#BKP do ------------Now it has their backpack from 1-ALL players...
            if Check[i].BKP[i].BeginnerSword == nil then -----If a player doesn't have the beginner tool then...
                A.Text = ..Check[i]..."He's got none." -----Say in public he has none and announce his name.(**All players** that do not have that tool.)
            end
        end
    end
    end

What's wrong?

1 answer

Log in to vote
0
Answered by
MrFlimsy 345 Moderation Voter
10 years ago

You have a for loop within a for loop, and they both use the same variable (i). This confuses the script. Try changing one of the variables.

Edit: I couldn't get your code to work. Try this:

function TimerEnd()
    wait(30)
    local Check = game.Players:GetChildren()
    for _,v in pairs(Check) do
        local found
        local BKP = v.Backpack:GetChildren()
        for __,x in pairs(BKP) do
            if x.Name == "BeginnerSword" then
                found = true
            end
        end
        if found == true then
            A.Text = v.Name.." has got none."
        end
    end
end
0
OMG what does _ do? and __? I do not know in pairs damnit...the last time I tried one of those it broke my game :( Overpride 0 — 10y
0
Yeah no thanks, I'm not doing that pear thing. Never trust a pear ;3 I'm gonna try the other one and if it doesn't work, I'll get back to ya xD Overpride 0 — 10y
0
Learning pairs/ipairs is essential if you want to be efficient in Lua. I recommend checking them out as soon as you have time. MrFlimsy 345 — 10y
View all comments (4 more)
0
just gr8 the game broke down LOL ok I'll try pears Overpride 0 — 10y
0
What does local mean? Can you explain? Overpride 0 — 10y
0
Your pears function does not work... :/ sigh Overpride 0 — 10y
Ad

Answer this question