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

My scripted Ship is moving and accelerating forever?

Asked by
alibix123 175
11 years ago

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.

01tool = script.Parent
02player = tool.Parent.Parent.Character
03playerc = player:getChildren()
04for _,v in pairs(playerc) do
05    if v:IsA("Part") then
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
11                        f = true
12                        debounce = false
13                        while f and wait() and not debounce do
14                            ship.BodyVelocity.velocity = ship.BodyVelocity.velocity + Vector3.new(10,0,0)
15                        end
View all 26 lines...

1 answer

Log in to vote
0
Answered by
Mowblow 117
11 years ago

Your ship is accelerating forever because you did not include code to slow it down! Example code to slow:

1if key == "s" or key == "S"  then
2f = true
3debounce = false
4while f and wait() and not debounce do
5ship.BodyVelocity.velocity = ship.BodyVelocity.velocity - Vector3.new(10,0,0)
Ad

Answer this question