Button1Down not firing within my script

I’m trying to make a system where when someone clicks, a boolean changes. With this script, none of the strings are printing, so the input isn’t even being detected and the booleans are not changing.
This is a Localscript inside of StarterCharacterScripts, and the rest of the code works.

I’ve tried using UserInputService instead but that also doesn’t seem to be working inside this script, how would I fix this?

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local movable = true

local UIS = game:GetService("UserInputService")

mouse.Button1Down:Connect(function()
	print("Clicked")
	if movable == false then
		movable = true
		print("clickedStart")
	elseif movable == true then
		movable = false
		print("clickedStop")
	end
end)
6 Likes

You have local movable set as true. Is this the boolean?

1 Like

Is this solved your problem?

local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Movable = true

local function onInputBegan(input, _gameProcessed)
	print("Clicked")
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		print("The left mouse button has been pressed!")
		if Movable then
			print("clickedStop")
			Movable = false
		else
			Movable = true
			print("clickedStart")
		end
	end
end

UserInputService.InputBegan:Connect(onInputBegan)

You can also change the input type UserInputType | Documentation - Roblox Creator Hub :yum:

Use the UserInputService event OnInputBegan, then you can check if the input type is a mouse click by doing if input.UserInputType == Enum.UserInputType.Button1Down

Hope this helps!

I don’t think there is a Button1Down type in the Enum. I think he meant MouseButton1

Maybe try using invisible buttons or something? Or is it something you need for a tool, sword in your inventory and you need to detect when they click to play an animation or something?

Yes, that’s the boolean I’m trying to change

Sorry about that, I’m on mobile right now so I’m not able to correct my code. Yes, it’s MouseButton1

No, it’s not for a tool. I could also use a keybind but that would stop mobile support.

What are you actually using Mouse or UserInputService?

Mouse in this script. I tried using UIS and it didn’t work, although that might have been a mistake on my side.

Try UIS again and see if it works on both mobile and PC, if it doesn’t, try ContextActionService.

Try using my code mentioned above.

Try testing it using a keybind. If it works, then it’s something to do with the clicking. If it doesn’t, it might be a problem on roblox’s side

I found out why, it’s because I link the function after the While True loop. Sorry!

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