Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is the Click Not Registering?

Pretty simple question but this code doesn't work sometimes.

local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()


function clickevent(data)
     print(data)
      script.Parent.UserInput:FireServer(data)
end

Mouse.Button1Down:Connect(function() clickevent("Down") end)
Mouse.Button1Up:Connect(function() clickevent("Up") end)
Mouse.Button2Down:Connect(function() clickevent("Down2") end)
Mouse.Button2Up:Connect(function() clickevent("Up2") end)

If I click very very quickly from the RMB to the LMB quickly, than LMB up doesn't register. How do I fix this?

3 comments

0

Just use Button1Click and Button2Click

0

Or UserInputService is better.

0

user input is better?

2 answers

✓ Accepted answer

Use UserInputService for this. It is much easier to use and much more powerful than mouse.

local userInputService = game:GetService("UserInputService")
local function clickEvent(clickType)
	script.Parent.UserInput:FireServer(clickType)
end

userInputService.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		clickEvent("Up")
	elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
		clickEvent("Up2")
	end
end)

userInputService.InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		clickEvent("Down")
	elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
		clickEvent("Down2")
	end
end)

Now I don't know enough of your script to help you with anything else but this. Start using UserInputService for future reference. It can be used with keys, mouse events, and more.

Learn More

1 comment

0

Thanks thats exactly what I needed! the code works perfectly

Using this method is almost unseen in modern roblox, seeing as the UIS (User Input Service) has been around for a while. I recommend using the new UIS, as this old method is very out of date and mainly broken. You can read more about UIS from the roblox developer forums, where they go into great detail on how to use services.

Or, if you are feeling super old schooled, just put a huge text button, problem solved! (That was a joke...)

Here is a link to a developer forum post on UIS: https://developer.roblox.com/en-us/api-reference/class/UserInputService

2 comments

0

This is a bad answer. You did not explain how to you use it just gave a link. This belongs in a comment not an answer.

0

Very well then, I was just trying to help.

This discussion is preserved as it was. New answers, comments, and votes are closed.