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

Make block invisible when Q key pressed?

I'm not exactly sure how to do this or if this script is correct but what I have so far is:

function onKeyDown(key)
	key:lower()
	if key == "q" then

game.Workspace.E.Transparency = 1
			end
			wait(0.03)
end

function onKeyUp(key)
	key:lower()
	if key == "q" then

game.Workspace.E.Transparency = 0
			end
			wait(0.03)
		end

2 answers

KeyDown and KeyUp is deprecated, meaning it can be removed or changed at any given moment. So instead of using those, use UserInputService.

Here;

local player=game.Players.LocalPlayer
local uis=game:GetService("UserInputService") --The only way to get UIS is by using :GetService

uis.InputBegan:connect(function(key) --Same thing as doing mouse.KeyDown, except it's InputBegan
	if key.KeyCode==Enum.KeyCode.Q then --Q can be any letter (and special keys, like ALT)
		workspace.E.Transparency=1 --doing workspace is the same as game.Workspace, just less typing
	end
end)

uis.InputEnded:connect(function(key) --same thing as mouse.KeyUp
	if key.KeyCode==Enum.KeyCode.Q then --Same thing
		workspace.E.Transparency=0
	end
end)

InputBegan

InputEnded

Put this in either StarterPack or StarterGui


local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse() --Did you define player?

Mouse.KeyDown:connect(function(Key)
	Key:lower()
	if Key == "q" then
		game.Workspace.E.Transparency = 1
	end
end

Mouse.KeyUp:connect(function(Key)
	Key:lower()
	if Key == "q" then
		game.Workspace.E.Transparency = 0
	end
end

3 comments

0

Umm, I think you meant KeyUp on the second one.

0

yah

0

UserInputService is better11!!!1

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