How to detect when a person is sitting down a seat and holding down a key

I need to create a script that detects when a person is sitting down a seat and holding down A or D.

I need to make it so that it rotates when a person is sitting down a key and holding down A or D.

The script i had in kind was


Humanoid:GetPropertyChangedSignal("Sit"):Connect(function()
    if Humanoid.Sit == true then

        -- Code goes here, does anybody know the function to receive a key held down?
        
   
        
    end
end)  ```

Also should i use cframe for rotating the part?
1 Like

Is this on the client or server?

You can try something like this. I hope its what you are looking for

local UserInputService = game:GetService("UserInputService")

Humanoid:GetPropertyChangedSignal("Sit"):Connect(function()
	UserInputService.InputBegan:Connect(function(input, processed)
		if Humanoid.Sit == true then
			if input.UserInputType == Enum.UserInputType.Keyboard then -- If the action was on a keyboard, continue.
				if input.KeyCode == Enum.KeyCode.A  then -- if the key matches then continue
					--Code if Player is sitting and holding A
					print("sit a")
				elseif input.KeyCode == Enum.KeyCode.D then
					--Code if Player is sitting and holding D
					print("sit d")
				else
					--Code if Player is sitting but not holding A or D
					print("none")
				end
			end
		end
	end)

	UserInputService.InputEnded:Connect(function(input, processed)
		if Humanoid.Sit == true then
			if input.UserInputType == Enum.UserInputType.Keyboard then -- If the action was on a keyboard, continue.
				if input.KeyCode == Enum.KeyCode.A then -- if the key matches then continue
					--Code if Player is sitting but not holding A anymore
					print("sit + not a anymore")
				elseif input.KeyCode == Enum.KeyCode.D then
					--Code if Player is sitting but not holding D anymore
					print("sit + not d anymore")
				else
					--Code if Player is sitting but not holding A or D anymore
					print("sit + none anymore")
				end
			end
		end
	end)
end)

Thank you so much!

That will help me so much.

1 Like

The script is a server script.

I don’t know if UserInputService will work on the Server but,
If you’re planning on making some kinda car system, do it all on the client and read some necessary values on the server (speed etc.)