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

Key comands script?

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

3 answers

✓ Accepted answer

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)
function onKeyDown(Key)
if Key=="Your key" then
--Your stuff
end
end

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.

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