Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

8 comments

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 :(

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

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.

0

just gr8 the game broke down LOL ok I'll try pears

0

What does local mean? Can you explain?

0

Your pears function does not work... :/ sigh

This discussion is preserved as it was. New answers, comments, and votes are closed.