UserInputService.InputBegan code sample incorrect comment format resulting in error on runtime

The code example documented on UserInputService.InputBegan contains arbitrary and incorrectly formatted comments which error on runtime.


The issue lies on the first and fourth line, see below.

// In order to use the InputBegan event, the UserInputService service must be used

and

// A sample function providing multiple usage cases for various types of user input

should be

-- In order to use the InputBegan event, the UserInputService service must be used

and

-- A sample function providing multiple usage cases for various types of user input

Image


Code sample w/ fix
    -- In order to use the InputBegan event, the UserInputService service must be used
    local UserInputService = game:GetService("UserInputService")
     
    -- A sample function providing multiple usage cases for various types of user input
    UserInputService.InputBegan:Connect(function(input, gameProcessed)
    	if input.UserInputType == Enum.UserInputType.Keyboard then
    		local keyPressed = input.KeyCode
    		print("A key is being pushed down! Key:",input.KeyCode)
    	elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
    		print("The left mouse button has been pressed down at",input.Position)
    	elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
    		print("The right mouse button has been pressed down at",input.Position)
    	elseif input.UserInputType == Enum.UserInputType.Touch then
    		print("A touchscreen input has started at",input.Position)
    	elseif input.UserInputType == Enum.UserInputType.Gamepad1 then
    		print("A button is being pressed on a gamepad! Button:",input.KeyCode)
    	end
    	if gameProcessed then
    		print("\tThis input began on top of a GuiObject!")
    	else
    		print("\tThis input did not begin on top of a GuiObject!")
    	end
    end)

Exact same issue on the following pages:

https://www.robloxdev.com/api-reference/event/UserInputService/InputChanged
https://www.robloxdev.com/api-reference/event/UserInputService/InputEnded

Someone needs to go back to Lua school.

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

1 Like

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