Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What should I use to make mouse input system?

Asked by 5 years ago

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)
0
The error says that MouseButton1Click is not a valid member of PlayerMouse FlonexVorry 28 — 5y

1 answer

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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

0
I see.. thank you so much :) FlonexVorry 28 — 5y
0
I edited the answer, check out some new stuff Ziffixture 6913 — 5y
Ad

Answer this question