Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to move something while key pressed and before its unpressed?

Asked by 4 years ago
Edited 4 years ago

i want to make brick named "cam" move when im still pressing key, not only when im pressed it but i getting error when im using InputEnded, what can i do?

UIS.InputBegan:Connect(function(key, gp)
    if key.KeyCode == HK then
            repeat wait(.1) move(key) until UIS.InputEnded()
    elseif key.KeyCode == HK2 then
            repeat wait(.1) move(key) until UIS.InputEnded()
        end
end)

function move(key)
    print(camera.Position.Y)
    if key.KeyCode == HK then
        if check() == true then
        local newpos = camera.Position.Y + 1
        camera.Position = Vector3.new(camera.Position.X,newpos, camera.Position.Z)
        end
    end
    if key.KeyCode == HK2 then
        if check2() == true then
        local newpos = camera.Position.Y - 1
        camera.Position = Vector3.new(camera.Position.X,newpos, camera.Position.Z)
        end
    end
end

function check()
    if camera.Position.Y < 221 then
        return true
    elseif camera.Position.Y == 221 then
        return end
end

function check2()
        if camera.CFrame.Y > 34 then
            return true
    elseif camera.Position.Y == 34 then
        return end
end

1 answer

Log in to vote
0
Answered by 4 years ago

Change your repeat loops. InputEnded is a signal, not a function. You're calling it like a function, which will error. However, we can use UIS:IsKeyDown(HK) to determine if the ke is being held or not. Since we're checking for it to be ended, we place a "not" in front of it.

repeat wait(.1) move(key) until not UIS:IsKeyDown(HK)
Ad

Answer this question