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

How to detect mouse click when mouse is held?

Asked by 3 years ago

I have a gui that appears when you hold down your left mouse button and I'm trying to make it so that if you hover your mouse over a button and let go of the left button, it does something, but it doesn't seem to work for me.

This is the code I'm using right now:

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

local GreenEntered = false

Green.MouseEnter:connect(function()
    GreenEntered=true
    ExpandGreen()
end)

Mouse.Button1Down:connect(function()
    if GreenEntered == true then
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed=100
    end
end

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

first of all, its good to realize that clicking a button is not possible unless you are indeed hovering over it. therefore, that GreenEntered variable is pointless.

Secondly, Button1Down is not an event of Mouse. Its an event of a button (actually the event is MouseButton1Down). Which is never declared here.

MouseEnter is also not an event of Green, which is never referenced either.

What you need is to reference the button. If your script is parented to the button, then you can type

local button = script.Parent

to get that button.

button.MouseButton1Up:Connect(function()

end)

MouseButton1Up is the event you are looking for. It fires when you let go of the left mouse button.

please accept and upvote, thank you:)

0
I didn't copy the entire script, but I can put it if you'd like. Also, its hard to detect the clicking of the left mouse button because to open the gui you have to hold down the left mouse button and when you let go the gui disappears. Bin_Latin 2 — 3y
Ad

Answer this question