✓ Accepted answer
This is your code:
Mouse.Button1Down:Connect(function()
Handle.Touched:Connect(function(touch)
if touch:IsA("Part") then
print('g')
end
end)
end)
When the left mouse button is pressed, it waits for the Handle to be touched. Of course, even if the mouse is released, it will still wait for the touched event to happen.
And you clearly want the touched event to only run if the left mouse button is currently being held down.
Handle.Touched:Connect(function(touch)
if game.UserInputService:IsMouseButtonPressed(0) then
if touch:IsA("Part") then
print('g')
end
end
end)
The :IsMouseButtonPressed() function of UserInputService will return true if the type of input you provide in the parentheses is currently being used. In this instance, you want the left mouse button, which is 0.
And for reference, this is the list of values that pertain to different types of input.
link
Here's the finished script.
local Tool = script.Parent
local Handle = Tool.Handle
local RemoteEvent = game:GetService("ReplicatedStorage").RemoteEvent
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
Handle.Touched:Connect(function(touch)
if game.UserInputService:IsMouseButtonPressed(0) and Tool.Parent = Character then
if touch:IsA("Part") then
print('g')
end
end
end)
2 comments
game.Players.LocalPlayer:GetMouse().Button1Down:Connect(function() -- code -- end)
^^^ He wants the Touched event to fire when the mouse is currently being held down, not as soon as it begins to be held down.