Im trying to found out how would you sense if the MouseButton1 has been clicked anywhere on the screen (not on a GUI). Any help would be appreciated.
(I'm using it for a punching script)
Im trying to found out how would you sense if the MouseButton1 has been clicked anywhere on the screen (not on a GUI). Any help would be appreciated.
(I'm using it for a punching script)
There's 2 ways of doing this, I recommend doing UserInputService. You could also use Player:GetMouse(), but I still recommend using UserInputService.
Player's Mouse
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.Button1Down:Connect(function()
print(mouse.Target, mouse.Hit, mouse.ViewSizeX, mouse.ViewSizeY, mouse.X, mouse.Y)
end)
Mouse.Target and Mouse.Hit is 3D Space and X and Y is screen.
UserInputService
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
print(game.Players.LocalPlayer:GetMouse().Hit) --// And the other things I showed in the other one.
end
end)
Hope this helped!
Using UserInputService is redundant in the case of detecting a Button1Down signal, anything in relation with the Mouse should be held within the Mouse. UserInputService is primarily used for bounding functions to keystroke events.
This discussion is preserved as it was. New answers, comments, and votes are closed.
4 comments
You could use the player's mouse or UserInputService.
How would I do that?
Please give me a trustable link with some info on that topicc.
Nvm found one https://developer.roblox.com/en-us/api-reference/class/Mouse