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

BodyVelocity doesnt work at first?

Asked by 4 years ago

Whenever The game first loads in, the keystrokes register, and the bodyvelocity changes, but the pos of ship doesnt change, I end up having to wait for 2mins for the pos to start changing? any reason to this?

--//movement V2

local ship = workspace.Player
local USI = game:GetService('UserInputService')
local BodyVelocity = Instance.new('BodyVelocity')
BodyVelocity.Parent = ship
BodyVelocity.Velocity = Vector3.new(0,0,0)
local holdingdown = false

--//Input
USI.InputBegan:Connect(function(keypress)
    holdingdown = true
    if holdingdown == true then
--//KEYS

--//W Key registration
        if keypress.KeyCode == Enum.KeyCode.W then
            print('W:P')
            BodyVelocity.Velocity = BodyVelocity.Velocity + Vector3.new(10,0,0)

--//A key registration
                    elseif keypress.KeyCode == Enum.KeyCode.A then
                        print('A:P')
                        BodyVelocity.Velocity = BodyVelocity.Velocity + Vector3.new(0,0,-10)

--//S key registration
                                elseif keypress.KeyCode == Enum.KeyCode.S then
                                    print('S:P')
                                    BodyVelocity.Velocity = BodyVelocity.Velocity + Vector3.new(-10,0,0)

--//D key registration
                                            elseif keypress.KeyCode == Enum.KeyCode.D then
                                                print('D:P')
                                                BodyVelocity.Velocity = BodyVelocity.Velocity + Vector3.new(0,0,10)
        end
    end
end)

--//Output
USI.InputEnded:Connect(function(keyrelease)
    holdingdown = false
--// KEYS

--// W key registraion
    if keyrelease.KeyCode == Enum.KeyCode.W then
        print('W:R')
        BodyVelocity.Velocity = BodyVelocity.Velocity - Vector3.new(10,0,0)
--//A key registration
                    elseif keyrelease.KeyCode == Enum.KeyCode.A then
                    print('A:R')
                    BodyVelocity.Velocity = BodyVelocity.Velocity - Vector3.new(0,0,-10)
--//S key registration
                                elseif keyrelease.KeyCode == Enum.KeyCode.S then
                                    print('S:R')
                                    BodyVelocity.Velocity = BodyVelocity.Velocity - Vector3.new(-10,0,0)
--//D key registration                            
                                            elseif keyrelease.KeyCode == Enum.KeyCode.D then
                                                print('D:R')
                                                BodyVelocity.Velocity = BodyVelocity.Velocity - Vector3.new(0,0,10)
    end
end)


0
What line doesnt work? JesseSong 3916 — 4y
0
Not really a line, its just that everything registers as it should, but the ships position doesnt change when the game first loads in for the first two minutes. joystuuu 7 — 4y

Answer this question