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

How to make a script where you press item with E and your mouse is hovering, it goes to backpack?

I've tried making an item where if you press E with your mouse over it, the tool in game.Lighting gets cloned and goes into your inventory. I've tried using mouse.Target and mouse.KeyDown to possibly make this happen, but the Output always puts these errors: "Attempt to connect failed: Passed value is not a function" and "attempt to call a nil value" <- This one occurs everytime I make a movement.

mouse = game.Players.LocalPlayer:GetMouse()
player = game.Players.LocalPlayer
enabled = true
itemname = nil

mouse.Move:Connect(function()
	if mouse.Target then
		if mouse.Target.Parent:FindFirstChild("ItemValue") then
			itemname = mouse.Target.Name
			function onKeyPress(inputObject, gameProcessedEvent)
				if not gameProcessedEvent then
    				if inputObject.KeyCode == Enum.KeyCode.E then
						if player.Backpack:findFirstChild(itemname) == true then
							if enabled == true then
								enabled = false
								local itemclone = game.Lighting[itemname]:clone()
								itemclone.Parent = player.Backpack
								enabled = true
							end
						end
					end
				end
			end
		else
			itemname = nil
		end
	else
	end
end)

1 answer

✓ Accepted answer

Nevermind guys, I figured out the problem.

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