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

How do you stop roblox auto equiping?

im trying to make it that if you pick up a item it does something this is printing something but its not doing it the part thats not working is

player.Backpack.ChildAdded:connect(function(instance)
	if instance.Name == game.Lighting.G:GetChildren()[1] or game.Lighting.Q:GetChildren()[1] or game.Lighting.R:GetChildren()[1] or game.Lighting.F:GetChildren()[1] or game.Lighting.G:GetChildren()[1]:Clone() then
		print(instance.Name .. " added to the backpack by unequip")	
	else
    	print(instance.Name .. " added to the backpack by item pickup")
	end
end)

it does the first print but doesnt do the second one why this is the full code

local player=game.Players.LocalPlayer
local y=1
local l=1
local c=1
local tools={
    E=game.Lighting.E:GetChildren()[1]:Clone();
    Q=game.Lighting.Q:GetChildren()[1]:Clone();
    R=game.Lighting.R:GetChildren()[1]:Clone();
    F=game.Lighting.F:GetChildren()[1]:Clone();
    G=game.Lighting.G:GetChildren()[1]:Clone();
}
local tool={
	game.Lighting.E:GetChildren()[1];
    game.Lighting.Q:GetChildren()[1];
    game.Lighting.R:GetChildren()[1];
    game.Lighting.F:GetChildren()[1];
    game.Lighting.G:GetChildren()[1];
}

game:GetService("UserInputService").InputBegan:connect(function(inputObject)
    if inputObject.KeyCode.Name=="Slash"then
		while l == 1 do
			y=3
			c=3
			player.Character.Humanoid:UnequipTools()
			player.PlayerGui.Invintory.Frame.Visible = false
			wait()
		end
		c=1
		y=1
		elseif inputObject.KeyCode.Name=="Return" then
		l = 2
		wait()
		l = 1
    	else
        local tool=tools[inputObject.KeyCode.Name]
        if tool then
            if y==1 then
                player.Character.Humanoid:EquipTool(tool)
                y=2
				if inputObject.KeyCode.Name == "E" then
                	player.PlayerGui.InventoryGui.Frame.Frame.E.BorderColor3=Color3.new(13/255,120/255,177/255)
				elseif inputObject.KeyCode.Name == "Q" then
					player.PlayerGui.InventoryGui.Frame.Frame.Q.BorderColor3=Color3.new(13/255,120/255,177/255)
				elseif inputObject.KeyCode.Name == "R" then
					player.PlayerGui.InventoryGui.Frame.Frame.R.BorderColor3=Color3.new(13/255,120/255,177/255)
				elseif inputObject.KeyCode.Name == "F" then
					player.PlayerGui.InventoryGui.Frame.Frame.F.BorderColor3=Color3.new(13/255,120/255,177/255)
				elseif inputObject.KeyCode.Name == "G" then
					player.PlayerGui.InventoryGui.Frame.Frame.G.BorderColor3=Color3.new(13/255,120/255,177/255)
				end
            elseif y==2 then
                player.Character.Humanoid:UnequipTools()
				if inputObject.KeyCode.Name == "E" then
                	player.PlayerGui.InventoryGui.Frame.Frame.E.BorderColor3=Color3.new(27/255,42/255,53/255)
					player.PlayerGui.InventoryGui.Frame.Frame.Q.BorderColor3=Color3.new(27/255,42/255,53/255)
					player.PlayerGui.InventoryGui.Frame.Frame.R.BorderColor3=Color3.new(27/255,42/255,53/255)
					player.PlayerGui.InventoryGui.Frame.Frame.F.BorderColor3=Color3.new(27/255,42/255,53/255)
					player.PlayerGui.InventoryGui.Frame.Frame.G.BorderColor3=Color3.new(27/255,42/255,53/255)
				elseif inputObject.KeyCode.Name == "Q" then
                	player.PlayerGui.InventoryGui.Frame.Frame.E.BorderColor3=Color3.new(27/255,42/255,53/255)
					player.PlayerGui.InventoryGui.Frame.Frame.Q.BorderColor3=Color3.new(27/255,42/255,53/255)
					player.PlayerGui.InventoryGui.Frame.Frame.R.BorderColor3=Color3.new(27/255,42/255,53/255)
					player.PlayerGui.InventoryGui.Frame.Frame.F.BorderColor3=Color3.new(27/255,42/255,53/255)
					player.PlayerGui.InventoryGui.Frame.Frame.G.BorderColor3=Color3.new(27/255,42/255,53/255)
				elseif inputObject.KeyCode.Name == "R" then
                	player.PlayerGui.InventoryGui.Frame.Frame.E.BorderColor3=Color3.new(27/255,42/255,53/255)
					player.PlayerGui.InventoryGui.Frame.Frame.Q.BorderColor3=Color3.new(27/255,42/255,53/255)
					player.PlayerGui.InventoryGui.Frame.Frame.R.BorderColor3=Color3.new(27/255,42/255,53/255)
					player.PlayerGui.InventoryGui.Frame.Frame.F.BorderColor3=Color3.new(27/255,42/255,53/255)
					player.PlayerGui.InventoryGui.Frame.Frame.G.BorderColor3=Color3.new(27/255,42/255,53/255)
				elseif inputObject.KeyCode.Name == "F" then
                	player.PlayerGui.InventoryGui.Frame.Frame.E.BorderColor3=Color3.new(27/255,42/255,53/255)
					player.PlayerGui.InventoryGui.Frame.Frame.Q.BorderColor3=Color3.new(27/255,42/255,53/255)
					player.PlayerGui.InventoryGui.Frame.Frame.R.BorderColor3=Color3.new(27/255,42/255,53/255)
					player.PlayerGui.InventoryGui.Frame.Frame.F.BorderColor3=Color3.new(27/255,42/255,53/255)
					player.PlayerGui.InventoryGui.Frame.Frame.G.BorderColor3=Color3.new(27/255,42/255,53/255)
				elseif inputObject.KeyCode.Name == "G" then
                	player.PlayerGui.InventoryGui.Frame.Frame.E.BorderColor3=Color3.new(27/255,42/255,53/255)
					player.PlayerGui.InventoryGui.Frame.Frame.Q.BorderColor3=Color3.new(27/255,42/255,53/255)
					player.PlayerGui.InventoryGui.Frame.Frame.R.BorderColor3=Color3.new(27/255,42/255,53/255)
					player.PlayerGui.InventoryGui.Frame.Frame.F.BorderColor3=Color3.new(27/255,42/255,53/255)
					player.PlayerGui.InventoryGui.Frame.Frame.G.BorderColor3=Color3.new(27/255,42/255,53/255)
				end
                y=1
            end
        end
    end
end)

game:GetService("UserInputService").InputBegan:connect(function(inputObject)
	if inputObject.KeyCode.Name == "C" then
		if c == 1 then
			player.PlayerGui.Invintory.Frame.Visible = true
			c=2
		elseif c == 2 then
			player.PlayerGui.Invintory.Frame.Visible = false
			c=1
		end
	end
end)
player.Backpack.ChildAdded:connect(function(instance)
	if instance.Name == game.Lighting.G:GetChildren()[1] or game.Lighting.Q:GetChildren()[1] or game.Lighting.R:GetChildren()[1] or game.Lighting.F:GetChildren()[1] or game.Lighting.G:GetChildren()[1]:Clone() then
		print(instance.Name .. " added to the backpack by unequip")	
	else
    	print(instance.Name .. " added to the backpack by item pickup")
	end
end)
while true do
player.PlayerGui.InventoryGui.Frame.Frame.E.NameE.Text = game.Lighting.E:GetChildren()[1].Name
player.PlayerGui.InventoryGui.Frame.Frame.F.NameF.Text = game.Lighting.F:GetChildren()[1].Name
player.PlayerGui.InventoryGui.Frame.Frame.G.NameG.Text = game.Lighting.G:GetChildren()[1].Name
player.PlayerGui.InventoryGui.Frame.Frame.Q.NameQ.Text = game.Lighting.Q:GetChildren()[1].Name
player.PlayerGui.InventoryGui.Frame.Frame.R.NameR.Text = game.Lighting.R:GetChildren()[1].Name
wait()
end

1 answer

✓ Accepted answer
if instance.Name == game.Lighting.G:GetChildren()[1] or game.Lighting.Q:GetChildren()[1] or game.Lighting.R:GetChildren()[1] or game.Lighting.F:GetChildren()[1] or game.Lighting.G:GetChildren()[1]:Clone() then

This if statement has 5 different conditions and is true if any of them are true.

  1. instance.Name == game.Lighting.G:GetChildren()[1] is false. A string is not an object.

  2. game.Lighting.Q:GetChildren()[1]is true. It exists.

  3. game.Lighting.R:GetChildren()[1]is true. It exists.

  4. game.Lighting.F:GetChildren()[1]is true. It exists.

  5. game.Lighting.G:GetChildren()[1]:Clone()is true. It exists.

The if statement will always be true. It looks like what you meant to do is check if instance.Name is the same as the name of any of those objects. The statement should read

local name=instance.Name
if name==game.Lighting.G:GetChildren()[1].Name or name==game.Lighting.Q:GetChildren()[1].Name or name==game.Lighting.R:GetChildren()[1].Name or name==game.Lighting.F:GetChildren()[1].Name or name==game.Lighting.G:GetChildren()[1].Name then

alternatively, you could just check if any of those objects contain a child called name:

local name=instance.Name
if game.Lighting.Q:FindFirstChild(name)or game.Lighting.R:FindFirstChild(name)or game.Lighting.F:FindFirstChild(name)or game.Lighting.G:FindFirstChild(name)then

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