Help with click event

So I have this code thats either suppose to:
A. tell when you click
B. Tell when your moues leaves a certain frame.

Now for the most part it works except it just doesnt detect when the user clicks and I dunno why. My code

Connections['ChangeTime'] = frame:FindFirstChild('TIme'):FindFirstChild('Time'):FindFirstChild('Time').MouseEnter:Connect(function()
    print('Entered')
    local clicked = 0
    
    Connections['ClickEnter'] = uis.InputBegan:Connect(function(input,g)
        if input.UserInputType == Enum.UserInputType.MouseButton1  then
            print('Clicked')
            clicked = 2
        end
    end)
    
    frame:FindFirstChild('TIme'):FindFirstChild('Time'):FindFirstChild('Time').MouseLeave:Once(function()
        clicked = 1
    end)
    

    
    
    repeat task.wait() until clicked ~= 0
    print(clicked)
    Connections['ClickEnter']:Disconnect()
    if clicked == 2 then
        local actualPo = UDim2.new(0,mouse.X - frame.AbsolutePosition.X,0,mouse.Y - frame.AbsolutePosition.Y)
        local z = Instance.new('Frame')
        z.Parent = frame:FindFirstChild('TIme'):FindFirstChild('Time'):FindFirstChild('Time')
        z.Position = actualPo
    end
end)

btw it does print click, but its always 1. The print inside the click event never prints either

2 Likes

Hi again!!!
I’m not quite too sure what’s the problem but you could try using Button1Down, like this

local mouse = player:GetMouse()

Connections['ClickEnter'] = mouse.Button1Down:Connect(function()
    print('Clicked')
    clicked = 2
end)
1 Like

Oh well yes I could do that

Btw forgot to mention this is for a plguin. Probably should have said that

But even so getting the mouse regularly or the way you do it with a plugin doesnt work, maybe its cause the mouse is hovering over the plugin widget and thats why

1 Like

Instead of just printing Clicked, print variable values so you can understand what caused (or didn’t cause) that section of code to run.

I just reread your code. Aren’t you setting clicked back to 1 every time right after you set it to 2?

   Connections['ClickEnter'] = uis.InputBegan:Connect(function(input,g)
        if input.UserInputType == Enum.UserInputType.MouseButton1  then
            print('Clicked')
            clicked = 2
        end
    end)
    
    frame:FindFirstChild('TIme'):FindFirstChild('Time'):FindFirstChild('Time').MouseLeave:Once(function()  --Why do you find 'Time' 3 times?
        clicked = 1
    end)

Its ok! I figured out that the click events wont work in a PluginWidget

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.