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

Make a part clickable when pressing a certain key?

Asked by 9 years ago
tile = script.Parent

local function onKeyDown( key )
    if key == q then
        tile.ClickDetector.MaxActivationDistance == 32
    end
end
end
mouse.KeyDown:connect(onKeyDown)

I have a ClickDetector on that part.

The purpose is that, if you click q while near the part, that part becomes clickable.

1 answer

Log in to vote
2
Answered by 9 years ago

You ALMOST had it! Your only problems were that you weren't using a LocalScript, never got the mouse, never lower-cased key (We do that so that we only have to check for 'q', and not 'Q' as well) and you forgot to wrap q in quotation marks to make it a string. Here's the fixed version:

local tile = game.Workspace.Tile
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

mouse.KeyDown:connect(function(key)
    key = key:lower()
    if key == "q" then
        tile.ClickDetector.MaxActivationDistance = 32
    end
end)
mouse.KeyUp:connect(function(key)
    key = key:lower()
    if key == "q" then
        tile.ClickDetector.MaxActivationDistance = 0
    end
end)
Ad

Answer this question