The part keeps rotating even when l press space bar

32 views Asked by At

This is an script that i created, however, it is not working. It is supposed to stop the rotation when i press the space bar:

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

it just keeps rotating when i press the space bar, i tried to change the order of the codes, i added the while part inside of the function and it didn`t work. But i noticed that the state variable never changes from true to false, it is like the stopAndGo function is never called.

1

There are 1 answers

0
user15611379 On

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