How can i script a part that rotates left or right whenever a key on a keyboard is pressed

  1. **What do you want to achieve? a script that makes a part rotate left or right whenever a key on a keyboard is pressed

  2. **What is the issue? i don’t how to add an event for when a key is pressed

I am not asking for an entire script but I want to know if there is any prebuild functions made for what i’m looking for

1 Like

UserInputService

1 Like
local Game = game
local Workspace = workspace
local UserInputService = Game:GetService("UserInputService")
local Part = Workspace:WaitForChild("Part")

local function OnInputBegan(InputObject, GameProcessed)
	if GameProcessed then return end
	local Input = InputObject.KeyCode.Name
	if Input == "E" then
		Part.CFrame *= CFrame.Angles(0, math.pi / 2, 0)
	elseif Input == "Q" then
		Part.CFrame *= CFrame.Angles(0, -math.pi / 2, 0)
	end
end

UserInputService.InputBegan:Connect(OnInputBegan)