I am trying to make a script that allows players to repair something by holding down the mouse button, but my mouse isn't getting detected. Why is this?
print("Phone box active")
PhoneBox = script.Parent
Broken = PhoneBox.Broken
CD = Broken.ClickDetector
UserInput = game:GetService("UserInputService")
RepairVal = PhoneBox.LocalScript.RepairVal
CD.MouseClick:connect(function(playerWhoClicked)
print("Broken clicked.")
UserInput.InputBegan:connect(function(key)
print("Input began")
if key.UserInputType == Enum.UserInputType.MouseButton1 then
print("Mouse button")
repeat
wait(0.1)
RepairVal.Value = RepairVal.Value + 0.1
until not UserInput:IsKeyDown(Enum.UserInputType.MouseButton1) and playerWhoClicked.Character
end
end)
end)

1 comment
I don't think UserInputService works on a server scripts. You might want to have a local script to detect the mouse down event and use remote event to fire to the server for changes.