如何在单击时获得信号

我正在尝试制作一个构建系统,但单击时它会生成多个部件。

local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
-- 代码
end
end)
点赞
用户8656749
用户8656749

代码本身是好的,没有什么问题。

local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
    -- 代码
    end
end)

考虑检查事件是否只定义了一次;避免在循环中绑定事件,以防止内存泄漏。

2021-10-17 19:43:25