This is what I am doing, but I have no idea how this will help me in preventing the vehicle from becoming occasionally (quite frequently) corrupted, like wheels breaking upwards and vehicle going into the ground.
@sporting_goods please check if you have some time and help me with some hints how to continue or what I am missing.
In a server script:
I clone a vehicle, position, name it, count the descendants and parent it to the workspace, then send a remote event to the client like:
local car = game.ServerStorage.Cars:FindFirstChild(v[1].ownership.SelectedCar.Value):Clone()
car:SetPrimaryPartCFrame((carSpawnPosition.CFrame + Vector3.new(0,2,0))* CFrame.Angles(0, math.rad(90), 0))
car.Name = v[1].Name.."_car"
local vehicleDescendantsTBL = car:GetDescendants()
local vehicleDescendantsCount = #vehicleDescendantsTBL
print("vehicleDescendantsCount : " .. tostring(vehicleDescendantsCount))
print("car.Name: " .. car.Name)
print("v[1].Name: " .. v[1].Name)
local carNumDescendants = car:FindFirstChild("NumDescendants")
carNumDescendants.Value = vehicleDescendantsCount
car.Parent = game.Workspace.RaceVehicles
checkVehicleDescendantsCountRE:FireClient(v[1],car.Name)
In a local script:
I count and print the descendants count.
local function onCheckVehicleDescendantsCountRequested(carName)
print("carName: " .. carName)
local vehicle = game.Workspace.RaceVehicles:WaitForChild(carName)
local vehicleDescendantsTBL = vehicle:GetDescendants()
local vehicleDescendantsCountClient = #vehicleDescendantsTBL
print("vehicleDescendantsCountClient: " .. tostring(vehicleDescendantsCountClient))
wait(1)
local vehicleDescendantsTBL = vehicle:GetDescendants()
local vehicleDescendantsCountClient = #vehicleDescendantsTBL
print("vehicleDescendantsCountClient: " .. tostring(vehicleDescendantsCountClient))
wait(1)
local vehicleDescendantsTBL = vehicle:GetDescendants()
local vehicleDescendantsCountClient = #vehicleDescendantsTBL
print("vehicleDescendantsCountClient: " .. tostring(vehicleDescendantsCountClient))
wait(1)
end
checkVehicleDescendantsCountRE.OnClientEvent:Connect(onCheckVehicleDescendantsCountRequested)
And this is the output I get:
from server:
vehicleDescendantsCount : 264
car.Name: purbanics_car
v[1].Name: purbanics
from client
carName: purbanics_car
vehicleDescendantsCountClient: 265
vehicleDescendantsCountClient: 328
vehicleDescendantsCountClient: 328
So how is this? You wrote that :
all of the parts will be instantaneously available on the server after the clone
but the server counts 264, then the client instantly after that counts 265 and after 1 sec delay counts 328 and again 328 after another sec delay.
???
Please help!
But anyway, this would not help me in any way to not get the vehicle become corrupted as I am just counting parts, not waiting for it to “materialize” properly.
What am I missing?
Should I wait before parenting the vehicle to the workspace for those parts to get created?
edit:
What seems to be happening is that the vehicle starts out with just 264 descendants, but then after it is parented to the workspace it goes up to 328 descendants quite quickly. In less then a sec.
I guess the vehicle chassis is creating springs and joints, etc.
I could weld the primary part of the vehicle to something (keeping it above the track) while waiting for the descendants count to stop increasing and then drop it on the track once it is all done.
Would this be a good solution?
I am using: INSPARE: AC6 Loaded - Build 6.52S2
How do other people solve this problem?