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

When I press the key "F" the part should get destroyed, what is wrong?

Asked by
xsodar 19
5 years ago

I need help with this script

This is the error "Workspace.Crystal.Script:5: attempt to index a nil value"

script.Parent.ClickDetector.MouseHoverEnter:Connect(function(player)

db = true

player:GetMouse().KeyDown:connect(function(k)
    k = k:lower()
    if k == "f" then
        if db == true then
            script.Parent:Destroy()
        end
    end
end)
end)

What is wrong here?

It supposed to when you hover your mouse over the part and then press "F" it should get destroyed.

Thanks

0
you're connecting a keyboard event to the mouse, that's the problem DeceptiveCaster 3761 — 5y
0
But if I want to make a script that when I have my mouse on a part and then press "F" it gets destoyed. How do I do that? xsodar 19 — 5y
0
embed a UserInputService or ContextActionService function inside of the ClickDetector function DeceptiveCaster 3761 — 5y
0
KeyDown in general is deprecated starmaq 1290 — 5y
View all comments (7 more)
0
you gotta use UserInputService starmaq 1290 — 5y
0
That's why it isn't working starmaq 1290 — 5y
0
Okay thank you, I'll try that. xsodar 19 — 5y
0
Np, did my answer help? starmaq 1290 — 5y
0
I'm working on it, but I think it will work. xsodar 19 — 5y
0
Use :Connect not :connect sirgrayknight 4 — 5y
0
ok starmaq 1290 — 5y

1 answer

Log in to vote
1
Answered by
starmaq 1290 Moderation Voter
5 years ago

KeyDown is deprecated, use the UserInputService.

You'll be using it like this.

script.Parent.ClickDetector.MouseHoverEnter:Connect(function(player)

    db = true

    game:GetService("UserInputService").InputBegan:Connect(function(k)

        if k.KeyCode == Enum.KeyCode.F then
            if db == true
                script.Parent:Destroy()
            end
        end

    end)
end)
0
ty starmaq 1290 — 5y
Ad

Answer this question