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

Make a part clickable when pressing a certain key?

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

✓ Accepted answer

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)

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