Hoe do i make a script so when players press a key on the keyboard it activates a function?
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.
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?