Button1Click is not a valid member of PlayerMouse "Instance"

I have a Gun System and all of them are Automatic, I wanted to make it semi by replacing mouse.Button1Down:connect(function() to mouse.Button1Click:connect(function()

Then this error shows up
image

The Script
mouse.Button1Down:connect(function() --Automatic--(Button1Down) --Semi--(Button1Click)
		local Humanoid = Player.Character and Player.Character.Parent ~= nil and Player.Character:FindFirstChildOfClass("Humanoid")
		if equipped then
			firing = true
			while firing == true do
				mouse.Button1Up:connect(function()
					firing = false
					Ammo.Value = Ammo.Value
					refreshGui()
				end)

I still have no idea how to fix this issue

1 Like

When you get an error like this, it literally means that Button1Click is not a valid member of that instance. So what you need to do is check if that event is even a part of that instance, in this case, it isn’t. Use the event Button1Down.

By the way, auto-fills are extremely useful. If it’s not enabled yet, you should enable it. Saves a lot of time and there’s also less chance of you misspelling a certain keyword or getting such error as this one.

Please replace connect() with Connect(), as the former is deprecated (i think).
Also, I don’t see any line mentioning Button1Click in your code.

2 Likes

Use UserInputService and just do

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input, gpe)
   if input.UserInputType == Enum.UserInputType.MouseButton1 then
      --Mouse1 Is being held down
   end
end)

UIS.InputEnded:Connect(function(input, gpe)
   if input.UserInputType == Enum.UserInputType.MouseButton1 then
      --Mouse1 Is not being held down anymore
   end
end)

You might wanna add a isAutomatic = false property and then do something like

local isAutomatic = false
local mouseHeldDown = false

local function shoot()
end

UIS.InputBegan:Connect(function(input, gpe)
   if input.UserInputType == Enum.UserInputType.MouseButton1 then
      mouseHeldDown = true
      if isAutomatic then
         if ammoCount > 0 then
            repeat
               shoot()

               task.wait(SHOOT_DELAY)
            until ammoCount <= 0 or mouseHeldDown == false
         end
      else
         if ammoCount > 0 then shoot() end
      end
   end
end)

UIS.InputEnded:Connect(function(input, gpe)
   if input.UserInputType == Enum.UserInputType.MouseButton1 then
      mouseHeldDown = false
   end
end)
1 Like

I don’t think there ever was :connect() but that’s a mistake I noticed as well. Don’t use any deprecated objects unless there’s not much wrong with them and they’re still usable (Just like the Draggable property for GUIs).

UserInputService can also be usable for this but there’s no difference really, UserInputService has more input events.

That code is a bit wrongly constructed as well, there’s definitely room for improvement.

This is a very bad idea, and your game will most likely crash. This is also considered a memory leak in my books. Since your connecting an event every moment, there will be a lot of memory used. Instead, remove the loop and use Button1Up:Wait().

2 Likes

Yeah, I’ve also noticed a crash when I spam-click the gun, especially when on high graphics. I will try this.

There was and still is. If you open the 2007 client, for eg, you’ll find there actually isn’t a :Connect function and that instead it was called :connect

There’s no mouse.Button1Click in localPlayer:GetMouse(), only mouse.Button1Down and mouse.Button1Up.