Why won't the mouse won't react to clicks?

Hello!

I’ve recently started trying to learn to make plugins to make my workload easier (especially to make paths for NPCs)

I’ve made a code that follows the mouse, everything works fine, then I’ve tried to make code that runs on click, and it didn’t work.

Here’s my code:

local plugin = PluginManager():CreatePlugin()
local mouse = plugin:GetMouse()

function onClicked()
    print("Hello World!")
end

mouse.Button1Down:Connect(onClicked)

Why won’t this work, and how to fix it?

Thanks in advance,
Mehdi

Try MouseButton1Down instead of Button1Down.

I normally call the function first for little scripts like this one. Try pasting this into your code instead of what you have:

local plugin = PluginManager():CreatePlugin()
local mouse = plugin:GetMouse()

mouse.MouseButton1Click:Connect(function()
    print("Hello World!")
end)

Hey, I don’t like using that, I find it less clear. But your script shows that (like the previous response I have to use “MouseButton1Click” instead of “Button1Click”.

I will immediately attempt to execute the content of your answer!
(30 character long-sentences)

image

image

Note the PluginMouse can only be used when the plugin has been activated using Plugin:Activate
Just saw that on the DevHub, trying…

The solution was to use the Plugin:Activate() event.
Read about it here!

2 Likes

I completely missed the fact you weren’t using a button :joy:
my bad :frowning:

I completely missed the fact you weren’t using a button :joy:
my bad :frowning:

That’s fine!