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

How to run functions on key press?

Asked by 7 years ago
Edited 7 years ago

The only way I know how to run functions in tool is on activated, how do I run then on key press? Here's the script I already made. The function is run on activated.

--alonzo12345

player = game.Players.LocalPlayer
tool = script.Parent
handle = tool.Handle
x = script.Chakram
spinning = false


function shieldup()
        wait(.5)
        local ff = Instance.new("ForceField")
        ff.Parent = tool.Parent
        game.Debris:AddItem(ff,2.5)
        local xc = x:Clone()
        xc.Parent = game.Workspace
        game.Debris:AddItem(xc,2.5)
        xc.CFrame = handle.CFrame
        local y = Instance.new("BodyVelocity")
        y.Parent = xc
        y.maxForce = Vector3.new(math.huge, math.huge, math.huge)
        y.Velocity = xc.CFrame.lookVector *0
        xc.loop:Play()
        while true do
            wait()
            xc.Position = handle.Position 
            xc.CFrame = handle.CFrame
        end

end

tool.Activated:connect(shieldup)

1 answer

Log in to vote
0
Answered by 7 years ago
function onKeyPress(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.R then
        --code here
    end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)

Copied from the wiki, hope this helped.

Ad

Answer this question