So I'm checking my output and when I click/release the clicking
variable prints as it should within the server script. For some reason though the code embodied in the function does not detect that so it does not keep breaking blocks.
The goal here is to be able to click and hold for a certain amount of time. Once the time limit is hit we break the block. If the mouse button is let go for any reason, the block will not be destroyed and the initial mouse holding timer will be reset.
--Server Script
local RE = game:GetService('ReplicatedStorage'):WaitForChild("PickaxeEvent") RE.OnServerEvent:Connect(function(player, clicking, target) print(clicking) if target ~= nil and target.Name ~= 'Bedrock' then while clicking == true do wait(1) print('Is clicking') --target:Destroy() end end end)
--Local Script
local RE = game:GetService("ReplicatedStorage"):WaitForChild("PickaxeEvent") local player = game:GetService("Players").LocalPlayer local mouse = player:GetMouse() local tool = script.Parent local handle = tool:WaitForChild("Handle") local active = false local clicking = false tool.Equipped:Connect(function() active = true game:GetService("UserInputService").InputBegan:Connect(function(input,gpe) -- Player is clicking if gpe then return end if input.UserInputType == Enum.UserInputType.MouseButton1 then clicking = true if active then -- while clicking do -- I tried to get it working with this as well... -- wait() -- print('clicking') -- end RE:FireServer(clicking, mouse.target) end end end) game:GetService("UserInputService").InputEnded:Connect(function(input,gpe) -- Player is not clicking if gpe then return end if input.UserInputType == Enum.UserInputType.MouseButton1 then clicking = false if active then RE:FireServer(clicking, mouse.target) end end end) end) tool.Unequipped:Connect(function() active = false clicking = false end)