问题是,当我快速双击时,武器会同时运行两次“while”进程(这使得只要按住左键,武器就会不确定地开火),从而使武器射击速度比预期更快。 它还以某种方式忽略了 InputEnded 函数(该函数指出当释放左键单击时, while 过程会产生),这显然会阻止这种“while”堆叠,因为显然,如果不先释放鼠标左键,则无法双击。 我链接了下面代码的过程。
conn = UIS.InputBegan:Connect(function(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
humanoid.WalkSpeed -= shoting
toolDebounce = true -- the boolean that must be true for the while process to run
while toolDebounce do
local startPosition = tool.Part.Position
local endPosition = mouse.Hit.Position
remoteEvent:FireServer(tool, startPosition, endPosition)
task.wait (debounceTime)
end
end
end)
conn2 = UIS.InputEnded:Connect(function(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
toolDebounce = false -- when the boolean in question is set to false, the while proccess yields. this only works if the interval between clicks is, aproximately, 0.4 seconds long
humanoid.WalkSpeed += shoting
end
end)
我们感谢任何帮助并将尝试。
我尝试在 InputBegan 函数之前添加一个“if not”子句,理论上,这将防止枪两次射击,因为 toolDebounce 布尔值仍然为 true。然而,它不起作用,因为枪仍然可以运行同时开火两次所需的 while 函数,尽管布尔值仍然为 true,忽略我之前所说的 if not 子句,不知何故。
local debounce=false
conn = UIS.InputBegan:Connect(function(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if debounce then return end
debounce=true
humanoid.WalkSpeed -= shoting
toolDebounce = true -- the boolean that must be true for the while process to run
while toolDebounce do
local startPosition = tool.Part.Position
local endPosition = mouse.Hit.Position
remoteEvent:FireServer(tool, startPosition, endPosition)
task.wait (debounceTime)
end
humanoid.WalkSpeed += shoting
debounce=false
end
end)
conn2 = UIS.InputEnded:Connect(function(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
toolDebounce = false -- when the boolean in question is set to false, the while proccess yields. this only works if the interval between clicks is, aproximately, 0.4 seconds long
end
end)