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

How can I make my drag tool detect when button1 has been clicked?

Asked by
Seyfert 90
6 years ago
Edited 6 years ago

I want to make it so when Button1Down is clicked the brick will get dragged AND while Button1Down is held it will continue to drag until the person lets go of Button1Down. I imagine Button1Down and Button1Up is used for this?

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

 mouse.Button1Down:connect(function()
     clicked = true
     while clicked do wait(0.01)
         if mouse.Target.Name == "Dough" then   
             mouse.Target.Position = mouse.Hit.p        
         end 
     end
 end)

 mouse.Button1Up:connect(function()
     clicked = false
 end)

What seems to happen is that I click once and hold and if I leave the mouse in place the brick will bounce up and down, as soon as I start to move the brick around it stops moving I think because the mouse moves too fast than the brick can move. How can I fix this?

Answer this question