Hold-Click Tools

There is probably a better solution, but what typically works for me is a while loop that causes the tool’s action to happen when a certain value is true.

Here is what I would suggest:

local tool = script.Parent
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

mouseDown = false

mouse.Button1Down:connect(function()
    mouseDown = true
end)

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

while true do
    wait()
    if mouseDown then
    	game.ReplicatedStorage.Events.EatDonut:FireServer()
    end
end

Edit: My bad, I completely forgot to put in a check to see if the player has the tool equipped or not (thank you, ChasingSpace). Make sure that’s added; the code you had to check that to begin with should work.

4 Likes