My scripted Ship is moving and accelerating forever?
So I made a hopperbin, that will control a basic ship, I'm taking it easy and it only moves on the Z axis but, when 'W' is pressed, then released, the velocity keeps increasing.
I know that a lot of this code is inefficient and messy, but I'm a beginner.
02 | player = tool.Parent.Parent.Character |
03 | playerc = player:getChildren() |
04 | for _,v in pairs (playerc) do |
06 | v.Touched:connect( function (hit) |
07 | if hit:IsA( "Seat" ) then |
08 | ship = hit.Parent.ship |
09 | function onKeyDown(key) |
10 | if key = = "W" or key = = "w" or string.byte(key) = = 113 or string.byte(key) = = 87 then |
13 | while f and wait() and not debounce do |
14 | ship.BodyVelocity.velocity = ship.BodyVelocity.velocity + Vector 3. new( 10 , 0 , 0 ) |
18 | function onSelected(mouse) |
19 | mouse.KeyDown:connect(onKeyDown) |
22 | tool.Selected:connect(onSelected) |