By part’s velocity, I am referring to it’s AssemblyLinearVelocity and it’s AssemblyAngularVelocity.
I am currently trying to make every part in a group stop suddenly, however, the AssemblyLinearVelocity remains what it previously was. Below I have provided the script that pertains to what I’m trying to do.
local eventcr = Instance.new("RemoteEvent")
eventcr.Name = "CruiseE"
eventcr.Parent = script.Parent
eventcr.OnServerEvent:connect(function()
if Plane.Cruising.Value == false then
print("Cruising")
Plane.Cruising.Value = true
Plane.Engine.FlyScript.Disabled = true
Plane.Engine.BodyVelocity.MaxForce = Vector3.new(0,0,0)
Plane.Engine.BodyVelocity.Velocity = Vector3.new(0,0,0)
Plane.Engine.BodyGyro.MaxTorque = Vector3.new(0,0,0)
Plane.Engine.Anchored = true
print("Now cruising... Setting velocity to 0.")
local parts = workspace.EA737.Body.Cabin:GetDescendants()
parts.AssemblyLinearVelocity = Vector3.new(0,0,0)
print("Complete")
elseif Plane.Cruising.Value == true then
Plane.Cruising.Value = false
Plane.Engine.FlyScript.Disabled = false
Plane.Engine.Anchored = false
end
end)
While the BodyVelocity correctly moves to ("0,0,0"), the individual part’s velocities remain the same. Important to note, there are models inside of models inside of models in this model (view below), and trying to make the script change each individual part’s velocity is simply illogical to do.
The goal is to get the player to be able to stand in and on the model without flinging off of it.
You can use a model’s :GetDescendants method in a loop to do this. So you’re on the right track, but it’s probably a bit expensive if you have a bunch of instances. It should work though, just try not to call it a bunch of times in a second.
local cabin = workspace:WaitForChild('Cabin')
eventcr.OnServerEvent:Connect(function()
if not Plane.Cruising.Value then
print("Cruising")
Plane.Cruising.Value = true
Plane.Engine.FlyScript.Disabled = true
Plane.Engine.BodyVelocity.MaxForce = Vector3.new(0,0,0)
Plane.Engine.BodyVelocity.Velocity = Vector3.new(0,0,0)
Plane.Engine.BodyGyro.MaxTorque = Vector3.new(0,0,0)
Plane.Engine.Anchored = true
print("Now cruising... Setting velocity to 0.")
for i,part in ipairs(cabin:GetDescendants()) do
if not part:IsA('Part') then
continue
end
part.AssemblyLinearVelocity = Vector3.new()
end
-- rest goes here
If you don’t want to iterate through every descendant of the cabin every time, you could probably make a table with all the parts like this:
local cabin = workspace:WaitForChild('Cabin')
local parts = {}
for i,part in ipairs(cabin:GetDescendants()) do
if part:IsA('Part') then
table.insert(parts, part)
end
end
-- then to reset every part's velocity,
for i,v in ipairs(parts) do
v.AssemblyLinearVelocity = Vector3.new()
end
I had to make a couple of adjustments to this as for some reason, it was not reading anything after this portion of the script (It is a long script that contains several different functions). Once I adjusted it to look like this:
local cabin = script.Parent.Body:WaitForChild('Cabin')
eventcr.OnServerEvent:Connect(function()
if not Plane.Cruising.Value then
print("Cruising")
Plane.Cruising.Value = true
Plane.Engine.FlyScript.Disabled = true
Plane.Engine.BodyVelocity.MaxForce = Vector3.new(0,0,0)
Plane.Engine.BodyVelocity.Velocity = Vector3.new(0,0,0)
Plane.Engine.BodyGyro.MaxTorque = Vector3.new(0,0,0)
Plane.Engine.Anchored = true
print("Now cruising... Setting velocity to 0.")
for i,part in ipairs(cabin:GetDescendants()) do
if not part:IsA('Part') then
continue
end
part.AssemblyLinearVelocity = Vector3.new(0,0,0)
print("Velocities have been put to 0!")
end
-- rest goes here
It seemed to pass over the script as if it was working, when I tested, however, the velocities did not change and I was still flung out. Is there anything specific I need to do with this script to make it work?
I added a print statement to see if it does in fact complete the function, and it does and appears to have completed it for the loop as well.
On another note, this function will be called only 1 time per server.
Any advice on why it’s not setting the part velocity to (0,0,0)? Thanks for your help!
You could just set the assemblyangularvelocity and the assemblylinearvelocity (I forgot the capitals) to 0.
You also don’t have to do, if not part then continue, you can just do a script where you check if the part is a part:
if part:IsA('Part') then
part.AssemblyLinearVelocity = Vector3.new(0,0,0)
print("Velocities have been put to 0!"
end
end
I’m trying all approaches, they all seem to work in output because I am having it print all names of the parts that it’s reading, and all are showing up. Only issue is, it still is not setting the velocities to 0.
I was thinking that this was when the aircraft is stopped until I read the ‘Cruising’ info.
If a Part is moving you can’t set its Velocity. It will still be moving so it’s LinearVelocity will go back to the value of it moving.
How fast is the cruising speed?
The plane is stopped (at least, it’s anchored and both the Body velocity and BodyGyro are set to 0. The cruise is activated by a button that anchors and zeros out the body velocity and BodyGyro.
I figured it out, just can’t really mark a solution because I figured it out on my own after messing around with the scripts provided here. I will post the code in a bit and mark it as a solution for anyone who has this same issue.
Since @SJxseCA forgot to put the solution, I will write it myself.
You have to set the network owner of the part to the server, then put the AsseblyLinearVelocity to 0, and finally give the networkship back to the player. The code should look something like this: