User Input Service Does not Work

Greetings fellow developers,

I am creating a script which changes a bool variable to false whenever D is pressed and to right whenever A is pressed. However, when I run the script the following error occurs.

--Services

local UIS = game:GetService("UserInputService")
local Run = game:GetService("RunService")

--Variables

local Sprite = script.Parent
local right = false

--Functions


local function SideHandler(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.A then
		right = false
	elseif inputObject.KeyCode == Enum.KeyCode.D then
		right = true
	end
end

--Loops
--Actions
UIS.InputBegan:Connect(SideHandler())

Try changing

UIS.InputBegan:Connect(SideHandler())

to

UIS.InputBegan:Connect(SideHandler)
1 Like

Thank you mate, that worked. Nice!

1 Like