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

Make block invisible when Q key pressed?

Asked by 8 years ago

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

Log in to vote
0
Answered by 8 years ago

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

Ad
Log in to vote
-1
Answered by 8 years ago

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
0
Umm, I think you meant KeyUp on the second one. LightningRoMan 100 — 8y
0
yah TheHospitalDev 1134 — 8y
0
UserInputService is better11!!!1 SimplyRekt 413 — 8y

Answer this question