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

How to remove a specific weapons if the player is not in the red team?

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?

Item marker

The problem is to line 08 and i don't know how fix this bug..

My testing 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:GetChildren()) do
				for i,v in pairs(AllGear:GetChildren()) do
					if v:FindFirstChild("Terrorist") then
						v:Destroy()
					end
				end
			end
		end
	end	
end)

8 comments

0

Define Beta Script? You should be able to work of this. Have you tried it?

0

Yes

0

And it not work

0

From glancing over the code, you have an "else" on line 5: if you want the script to work if the player is on the red team, I recommend you removed that line. :P

0

It should not remove the weapons of the player in red team.. Just if the player is not in the red team so i don't remove this lines. The problem is to line 08 and i don't know how fix this bug..

0

What's AllGear? And does whatever in AllGear (the current instance being iterated through) have a child named "Terrorist"? If not, then that's more than likely your problem.

0

The code is fine, from what I see. The code is looking through everything in the player's backpack for "Terrorist". Are you sure that value is present?

0

Yes, in the weapons than i want destroy if the player is not in the red team, but not in all weapons

1 answer

✓ Accepted answer

Based upon what I've read in your script, you're searching through all the members of your tools and then looking for a value inside those children. What you should be doing is finding if the value is in the tool itself. 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
            for i,AllGear in pairs(NewPlayer.Backpack:GetChildren()) do
		if AllGear:FindFirstChild("Terrorist") then --Change was around here.
			AllGear:FindFirstChild("Terrorist"):Destroy()
		end
            end
        end
    end 
end)

I also took the liberty of turning your if-else statement into a simple if statement by changing your == operator to ~=

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