I’m trying to make a simple Hold Down to Fire Event, however GetMouse() does not seem to recognize the buttons i am pressing regardless when i have the tool equipped.
local __MOUSE = __LOCALPLAYER:GetMouse()
local __TOOL = script.Parent
local __TIME = __TOOL:WaitForChild("__TIMEITTAKES")
local __EVENT = __TOOL:WaitForChild("__PLACE")
local __ISHOLDING : BoolValue? = false
__MOUSE.Button2Down:Connect(function()
__ISHOLDING = true
end)
__MOUSE.Button2Up:Connect(function()
__ISHOLDING = false
end)
coroutine.wrap(function()
while __ISHOLDING == true do
task.wait()
__TIME.Value += 1
print(__TIME.Value)
if __TIME.Value == 10 then
__EVENT:FireServer()
break
end
end
end)()
I believe it is this. The while loop never runs because __ISHOLDING is false in the beginning.
local __MOUSE = __LOCALPLAYER:GetMouse()
local __TOOL = script.Parent
local __TIME = __TOOL:WaitForChild("__TIMEITTAKES")
local __EVENT = __TOOL:WaitForChild("__PLACE")
local __ISHOLDING : BoolValue? = false
__MOUSE.Button2Down:Connect(function()
__ISHOLDING = true
while __ISHOLDING == true do
task.wait()
__TIME.Value += 1
print(__TIME.Value)
if __TIME.Value == 10 then
__EVENT:FireServer()
break
end
end
end)
__MOUSE.Button2Up:Connect(function()
__ISHOLDING = false
end)
Not sure why it isn’t breaking, but just add another condition.
local __MOUSE = __LOCALPLAYER:GetMouse()
local __TOOL = script.Parent
local __TIME = __TOOL:WaitForChild("__TIMEITTAKES")
local __EVENT = __TOOL:WaitForChild("__PLACE")
local __ISHOLDING : BoolValue? = false
__MOUSE.Button2Down:Connect(function()
__ISHOLDING = true
while __ISHOLDING == true and __TIME.Value < 10 do
task.wait()
__TIME.Value += 1
print(__TIME.Value)
if __TIME.Value == 10 then
__EVENT:FireServer()
end
end
end)
__MOUSE.Button2Up:Connect(function()
__ISHOLDING = false
end)