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)

3 comments

0

To make this easier for you: Button1Down, Button1Up of the Mouse exists. Wiki it

0

Or use tool.Activated and be smart

0

tool.Activated does essentially what im doing here. The problem isn't detecting the mouse exactly. More so as the problem is when the value gets replicated to the server script. The server script simply ignores that the boolean is true/false after the first click. Making the while loop run indefinitely.