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

What should I use to make mouse input system?

How to make mouse input? Why is my script is not working?

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

Mouse.MouseButton1Click:connect(function()
	print("LOL")
end)

1 comment

0

The error says that MouseButton1Click is not a valid member of PlayerMouse

1 answer

✓ Accepted answer

Your issue is you're using a clickEvent ment for a Gui Object meaning it will fire when a Gui was click by the mouse, you should be using Button1Down instead for as the default event

local player = game:GetService("Players").LocalPlayer --// more efficient method, use this
local cursor = player:GetMouse --// I prefer cursor:)

cursor.Button1Down:Connect(function()
   pcall(function()
      print(cursor.Hit.p.." - '"..cursor.Target.Name.." ("..cursor.Target.ClassName) --// try this out
   end)
end)

mouse.Hit.p will give you a Vector3 position of the mouse in a 3D worldspace, this is useful in some scenarios.

mouse.Target is what the mouse is hovering over, sometimes this can be nil so we use pcall to make sure the script keeps running

2 comments

0

I see.. thank you so much :)

0

I edited the answer, check out some new stuff

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