即使我按空格键,零件仍会旋转

问题描述 投票:0回答:1

这是我创建的脚本,但是它不起作用。当我按下空格键时,它应该停止旋转:

local spinning = script.Parent
local state = true

local function stopAndGo()
    state = not state
end

game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessedEvent)
    if not gameProcessedEvent and input.KeyCode == Enum.KeyCode.Space then
        stopAndGo()
    end
end)

while true do
    if state then
        spinning.CFrame = spinning.CFrame * CFrame.fromEulerAnglesXYZ(255, 0, 0)
    end
    wait(0.03)
end

当我按空格键时它会继续旋转,我尝试更改代码的顺序,我在函数内部添加了 while 部分,但它不起作用。但我注意到状态变量永远不会从 true 变为 false,就像 stopAndGo 函数从未被调用一样。

lua rotation roblox keycode
1个回答
0
投票

spawn(function()
while true do
    if state then
        spinning.CFrame = spinning.CFrame * CFrame.fromEulerAnglesXYZ(255, 0, 0)
    end
    wait(0.03)
end
end)

© www.soinside.com 2019 - 2024. All rights reserved.