Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can i make my Space Ship with BodyThrust Stop???

So i made a space ship, which uses a script to find the Throttle of a Vehicle Seat...anyway i put a Part called "Engine", with a BodyThrust inside of it. So it works fine but, i cannot get it to stop, even if i anchor/unanchor the Ship, here is the script...How i can i fix it to make it stop when the throttle hits Zero???

Seat = script.Parent.VehicleSeat
Engine = script.Parent.Engine

script.Parent.VehicleSeat.Changed:connect(function()
	if script.Parent.VehicleSeat.Throttle == 1 then
		script.Parent.Engine.BodyThrust.Force = Vector3.new(0,0,-9999110.09)--The Ship is really big so i need lots of Force to even move
	end
end)

script.Parent.VehicleSeat.Changed:connect(function() --This is the function where it should be stopping.
	if script.Parent.VehicleSeat.Throttle == 0 then 
		script.Parent.Engine.BodyThrust.Force = Vector3.new(0,0,0)--So how can i make the ship stop moving?
	end
end)

script.Parent.VehicleSeat.Changed:connect(function()
	if script.Parent.VehicleSeat.Throttle == -1 then
		script.Parent.Engine.BodyThrust.Force = Vector3.new(0,0,9999110.09)--The Ship is really big so i need lots of Force to even move
	end
end)

1 comment

2

You don't have to have three different changed event connections to use the if statements. You can put all the if statements in the same event connection. Then you could use elseif, too.

1 answer

Try this:

Seat = script.Parent.VehicleSeat
Engine = script.Parent.Engine
BrakeSpeed = 10 --Change this to brake faster/slower
MoveSpeed = 9999110.09 --The Ship is really big so it needs lots of Force to even move

if not Engine:FindFirstChild("BodyVelocity") then
	BodyVelocity = Instance.new("BodyVelocity", Engine)
	BodyVelocity.MaxForce = Vector3.new(0, 0, 0)
	BodyVelocity.Velocity = Vector3.new(0,0,0)
else
	BodyVelocity = Engine:FindFirstChild("BodyVelocity")
end

script.Parent.VehicleSeat.Changed:connect(function()
	if script.Parent.VehicleSeat.Throttle == 1 then
		BodyVelocity.MaxForce = Vector3.new(0, 0, 0)
		Engine.BodyThrust.Force = Vector3.new(0, 0, -MoveSpeed)
	elseif script.Parent.VehicleSeat.Throttle == 0 then 
		BodyVelocity.MaxForce = Vector3.new(BrakeSpeed, BrakeSpeed, BrakeSpeed)
		Engine.BodyThrust.Force = Vector3.new(0,0,0)
	elseif script.Parent.VehicleSeat.Throttle == -1 then
		BodyVelocity.MaxForce = Vector3.new(0, 0, 0)
		Engine.BodyThrust.Force = Vector3.new(0, 0, MoveSpeed)
	end
end)

1 comment

0

You should mark this answer as correct or state why it isn't correct

This discussion is preserved as it was. New answers, comments, and votes are closed.