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

bad argument #1 to 'pairs' (table expected, got Object)?

In reality I want that is the player is not in the red team weapons with a marker "Terrorist" this destroys, how to make this? How to fix my script?

workspace.ChildAdded:connect(function(object)
	local NewPlayer = game.Players:playerFromCharacter(object)
	if NewPlayer then
		if NewPlayer.TeamColor == BrickColor.new("Bright red") then
		else
			for i,AllGear in pairs(NewPlayer.Backpack) do
				for i,v in pairs(AllGear) do
					if v:FindFirstChild("terroriste") then
						v:Destroy()
					end
				end
			end
		end
	end	
end)

1 answer

✓ Accepted answer

Well the problem here is simple. You're referencing the object, instead of referencing the object's children. Here's a fixed version of your code:

workspace.ChildAdded:connect(function(object)
    local NewPlayer = game.Players:playerFromCharacter(object)
    if NewPlayer then
        if NewPlayer.TeamColor == BrickColor.new("Bright red") then
        else
            for i,AllGear in pairs(NewPlayer.Backpack:GetChildren())) do
                for i,v in pairs(AllGear:GetChildren())) do
                    if v:FindFirstChild("terroriste") then
                        v:Destroy()
                    end
                end
            end
        end
    end 
end)

3 comments

0

Omg i'm really stupid....Thank you very much for your help I appreciate it enormously!

0

What changes did you make? I see the fix, but the OP may not; could you point it out for future reference, and explain what it does?

0

Thanks for the input Stigma. The change I made was I added :GetChildren() to both AllGear and Backpack on lines 06 and 07.

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