Why isnt inputbegan working?

I want to make a script to detect when the mouse button is held down, but it wont work. Here is my code

local UIS = game:GetService("UserInputService")
local holding = false

UIS.InputBegan:Connect(function(io)
	if io.UserInputType == Enum.UserInputType.MouseButton1  then
		holding = true
		print("began")
	end
end)

I’ve tried putting it in a local script inside of the playerscripts folder and a normal script inside a part in the work space.

1 Like

no errors or anything? (keep it in the local script form)

There were no errors when i tried to run the script.

Try putting a print statement before the function to see if the code actually runs

I got it working after i took a closer look, apparently in needs to be in the “starterplayerscripts” folder. Putting it in “StarterPlayer” does not work

1 Like

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