hello! We have a script that transfers a vehicle from ServerStorage to Workspace but when spawned it is either anchored or the scripts are disabled. In the script it even has a line to make it unanchored but it still doesn’t work.
We would like to try to make the code work to make the train unanchored or let the vehicle move instead of it being frozen.
In terms of your scripts, have them enabled (not disabled) the whole time. They can’t run in the storage folders so there’s no need to mess around enabling or disabling them.
In terms of anchored parts, we have every part in the train anchored. Before unanchoring, we create welds between each part of each carriage to a central root part. You can use WeldConstraint for this, or create a Weld instance. Once done, we unanchor it.
The general principle looks like this:
local train = class153 -- we have one script to do all functionality so this is set by what you select on the GUI
for _, carriage in ipairs( train:GetChildren() ) do
if not carriage:IsA( 'Model' ) then
continue
end
local root = carriage:FindFirstChild( 'CarriageRoot' )
-- IMPORTANT create a part called CarriageRoot in each carriage or replace with a part you want to weld to
for _, descendant in ipairs( carriage:GetDescendants() ) do
if not descendant:IsA( 'BasePart' ) or descendant == root then
continue
end
local weld = Instance.new( 'WeldConstraint' )
weld.Part0 = root
weld.Part1 = descendant
weld.Parent = descendant
descendant.Anchored = false
end
root.Anchored = false
end
You can do other things here too, so for example we set up stuff with the lights, we sort out the seats, we make sure everything has the right physical properties, etc. Using a loop like this makes it pretty easy, and in your case you’d pop it in where you current Anchored = false line is.
If your trains have a different hierarchy where carriages aren’t models or they aren’t direct children of the train model then obviously edit those appropriately. This is just to give you a general idea of how it works.