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

Key comands script? [closed]

Asked by 10 years ago

Hoe do i make a script so when players press a key on the keyboard it activates a function?

Locked by evaera

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

3 answers

Log in to vote
0
Answered by
MrNicNac 855 Moderation Voter
10 years ago

In a LocalScript, you can use the :GetMouse() event of the local player and connect a function to register when the KeyDown/KeyUp event fires. Generally, you can put this script in the StarterGui or StarterPack.

I prefer to use KeyUp, when either can be used, as some of the binded keys that wont fire using KeyDown will register fine.

local player = Game.Players.LocalPlayer;
local mouse = player:GetMouse();

mouse.KeyUp:connect(function()
-- Code
end)
Ad
Log in to vote
0
Answered by 10 years ago
function onKeyDown(Key)
if Key=="Your key" then
--Your stuff
end
end
Log in to vote
0
Answered by
neoG457 315 Moderation Voter
10 years ago

local enabled = true Player = script.Parent.Parent

mouse = Player:GetMouse() run = game:GetService("RunService") function onKeyDown(key) if not enabled then return end enabled = false Key = key:lower() if key == "x" then -- change the key

A Script Used By Friaza himself.