UserInputService:GetDeviceAcceleration code sample botched quotations and missing then keyword

The code sample documented on the UserInputService:GetDeviceAcceleration function page has multiple issues which prevent the script from running.


The issues lie on the first and fifth line.

First line: local UserInputService = game:GetService(“UserInputService”)

Should be: local UserInputService = game:GetService("UserInputService")

Fifth line: if accelerometerEnabled

Should be: if accelerometerEnabled then

Image

Error

(excuse line numbers, had whitespace)

image

image


Code sample w/ correct changes
local UserInputService = game:GetService("UserInputService")

local accelerometerEnabled = UserInputService:AccelerometerEnabled()

if accelerometerEnabled then
	local acceleration = UserInputService:GetDeviceAcceleration().Position
	print(acceleration)
else
	print("Cannot get device acceleration because device does not have an enabled accelerometer!")
end

Also noticed an issue on line three.

Should be: local accelerometerEnabled = UserInputService.AccelerometerEnabled

Currently is: local accelerometerEnabled = UserInputService:AccelerometerEnabled()

Fixed code sample
local UserInputService = game:GetService("UserInputService")

local accelerometerEnabled = UserInputService.AccelerometerEnabled

if accelerometerEnabled then
	local acceleration = UserInputService:GetDeviceAcceleration().Position
	print(acceleration)
else
	print("Cannot get device acceleration because device does not have an enabled accelerometer!")
end

Thank you for the report. This issue has now been resolved.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.