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

InputObject:GetPropertyChangedSignal("Position") will not work properly on MouseButton1?

Asked by 2 years ago
Edited 2 years ago

So I have a userinputservice going on in my script

and I tried to set a

 InputObject:GetPropertyChangedSignal("Position") 

Apparently this works perfectly fine on Mobile

But when it comes to desktop it fires once which is when the Input has ended

Does anyone know why this is?

Heres my code

ImageButton.InputBegan:Connect(function(InputObject)



    if InputObject.UserInputType == Enum.UserInputType.MouseButton1 or InputObject.UserInputType == Enum.UserInputType.Touch then
        InputObject:GetPropertyChangedSignal("Position"):Connect(function()
            print('Mouse has moved')
        end)
    end

end)

To be honest this code does work on Desktop too but the printing seems to stack meaning the events are stacking

which is a memory leak?

Anyone know whats going on?

1 answer

Log in to vote
1
Answered by
Puppynniko 1059 Moderation Voter
2 years ago

what you have to do is disconnect the events

local Connection = nil
ImageButton.InputBegan:Connect(function(InputObject)
    if InputObject.UserInputType == Enum.UserInputType.MouseButton1 or InputObject.UserInputType == Enum.UserInputType.Touch then
        Connection = InputObject:GetPropertyChangedSignal("Position"):Connect(function()
            print("MouseMoved")
        end)
    end
end)
ImageButton.InputEnded:Connect(function()
    if Connection then
        Connection:Disconnect()
        Connection = nil
    end
end)

0
I have already tried this but the problem I am facing right now is that this script will not fire the position event for some reason unlike mobile and I still don't know why but it just wont fire them as they are being dragged for some reason the event seems to fire only when the Input is ended Overseer_Prince 188 — 2y
0
Not only that when you wrap the event inside of the condition that its either gotta be a MouseButton1 or Touch it starts doing that however when it is outside of the condition it does not do that do you know why this is happening to me? Overseer_Prince 188 — 2y
0
im pretty sure ContextActionService is better at handling TouchInputs and Keyboard input aswell as gamepad inputs Puppynniko 1059 — 2y
0
and you can try to get mouse postion on screen when clicked basically the same thing Puppynniko 1059 — 2y
View all comments (5 more)
0
Or when the mouse moves Puppynniko 1059 — 2y
0
Is contextactionservice good for GUI's I have always thought of contextactionservice as something other than GUIS like weapons or creating buttons systematically Overseer_Prince 188 — 2y
0
Also there is no input changed event specifically made for context action service which I had to use MouseMovement and Enum.UserInputType.Touch for that and you know Input Changed is probably better than listing those two since there could be other input changed events Overseer_Prince 188 — 2y
0
Also I have noticed ContextActionService performs poorly with GUI's Input Began like the context action dosen't detect the input began on the gui so like smh Overseer_Prince 188 — 2y
0
cant you just detect when clicked then Track the mouse Position and stop when ContextActionService ObjectState changed to end?? Puppynniko 1059 — 2y
Ad

Answer this question