Im trying to make a keyboard input to make the vehicle do an action but everything I tried from tutorials do not work.

The script is a Local scripts and I have tried it as a normal. I understand Locals are used to detect player input.

The script is attached to the seat itself.

--Truck Parts
local seat = script.Parent
local truck = seat.Parent
local craneExtended = false

--Crane Parts
local CraneDrive = truck.TruckBase.CraneDrive
local ForeCraneDrive = truck.Crane.CraneUpperArm.ForeCraneDrive

--Input
local UserInputService = game:GetService("UserInputService")
	
local function operateCrane(actionName, userInputState, inputObject)
	if userInputState == Enum.UserInputState.Begin then
		print("R was pressed")
		if craneExtended == false then
			CraneDrive.TargetAngle = -110
			ForeCraneDrive.TargetAngle = -70
			craneExtended = true
		else		
			CraneDrive.TargetAngle = 0
			ForeCraneDrive.TargetAngle = 0
			craneExtended = false
		end
	end
end	

game.ContextActionService:BindAction("keyPress", operateCrane, false, Enum.KeyCode.R)

3 comments

0

use :GetService() to get CAS

0

thats context action service

0

Can someone expand please and give an example?