Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
BiIinear 104
4 years ago

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

Log in to vote
1
Answered by
BiIinear 104
4 years ago

Nevermind guys, I figured out the problem.

Ad

Answer this question