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

My part is not moving in a diagonal direction when two buttons are pressed at the same time?

Asked by 2 years ago
function droneMovement(player,keypressed,direction)
    local dronecframe = drone.CFrame

    if keypressed == "w" then
        Bodypos.Position = dronecframe:PointToWorldSpace(Vector3.new(0,0,-3)) 


    elseif keypressed == "a" then
        Bodypos.Position = dronecframe:PointToWorldSpace(Vector3.new(-3,0,0))


    elseif keypressed == "s" then
        Bodypos.Position = dronecframe:PointToWorldSpace(Vector3.new(0,0,3))

    elseif  keypressed == "d" then
        Bodypos.Position = dronecframe:PointToWorldSpace(Vector3.new(3,0,0))

    end


    if direction == "Right" then
        BodyGyro.CFrame = BodyGyro.CFrame * CFrame.new(Bodypos.Position) * CFrame.Angles(0,math.rad(-2.5),0)
    end

    if direction == "Left" then
        BodyGyro.CFrame = BodyGyro.CFrame * CFrame.new(Bodypos.Position) * CFrame.Angles(0,math.rad(2.5),0)
    end



end



droneserver.OnServerEvent:Connect(droneMovement)

thats the ^ server script where everything moves in the server

function drone.dronemovement()
    local validKeys = {
        ["W"] = function()
            droneserver:FireServer("w") 
        end,
        ["A"] = function()
            droneserver:FireServer("a") 
        end,
        ["S"] = function()
            droneserver:FireServer("s") 

        end,
        ["D"] = function()
            droneserver:FireServer("d") 

        end,
    }


    while true do

        local arr = userinputservice:GetKeysPressed()

        for _,key in pairs(arr) do

            local check = validKeys[key.KeyCode.Name]
            if check then
                check() 
            end
        end
        wait()


    end




end 

This is the module script where i am trying to get the part to move when in a diagonal direction when when for example W+A is pressed at the same time on the keyboard.

Answer this question