How would I make a tool do something while the mouse button is down, currently I am using the “Activated” function for tools meaning I have to keep clicking so how could I make it so I can just hold down and something happens until the button is lifted.
Thank you if you help, kind regards.
Zonix
Hello, Zonix_Official!
You can have a variable for holding down and use a while loop to keep triggering the function!
this should do what you’re looking for.
local mouse = player:GetMouse
local doing = false
mouse.Button1Down:Connect(function()
doing = true
while doing do
--code here
end
end)
mouse.Button1Up:Connect(function()
doing = false
end)
or you can do this:
local doing = false
script.Parent.Activated:Connect(function()
doing = true
while doing do
--code here
end
end)
script.Parent.Deactivated:Connect(function()
doing = false
end)
6 Likes
Thank you so much for this help!