I have a script almost working, but it doesn’t work while the vehicle is on the ground.
script: (in every block, it is also very laggy)
local ispes = false
function pes()
local g = script.Parent:GetChildren()
for i = 1, #g do
local touch = script.Parent.PrimaryPart.Touched:Connect(function() end)
local touching = script.Parent.PrimaryPart:GetTouchingParts()
if g[i]:IsA("WeldConstraint") then
for i = 1, #touching do
if (touching[i]:IsA("VehicleSeat") or touching[i].Parent:IsA("VehicleSeat")) and not touching[i]:IsDescendantOf(workspace.Bases) then
script.Parent.IsSeat.Value = touching[i].Parent.Name
ispes = false
elseif not touching[i]:IsDescendantOf(script.Parent) and touching[i]:IsDescendantOf(workspace.PlacedObjects) and ispes == false then
script.Parent.IsSeat.Value = touching[i].Parent.Parent.IsSeat.Value
elseif touching[i].Name == "Terrain" and not touching[i]:IsDescendantOf(workspace.PlacedObjects) then
script.Parent.IsSeat.Value = ""
ispes = true
elseif (touching[i]:IsDescendantOf(workspace.PlacedObjects) and touching[i].Parent.Parent.IsSeat.Value == "") and ispes == true then
script.Parent.IsSeat.Value = ""
end
end
end
if script.Parent.IsSeat.Value == "" and script.Parent:IsDescendantOf(workspace.PlacedObjects) then
script.Parent.Parent = workspace.PlacedObjects
else
script.Parent.Parent = workspace.PlacedObjects[script.Parent.IsSeat.Value]
end
end
end
game:GetService("RunService").Heartbeat:Connect(pes)
the IsSeat Value is the seat that the blocks are attached to
at 0:22 i was un-anchoring the seat
at the end of it some blocks go outside the seat and the IsSeat value is set to nil.
If all of the vehicle’s parts is in a model, you could probably use :GetDescendants() and iterate through it comparing the current part in the iteration with the part you’re trying to find.
ok. I worded the title wrong. But thanks for letting me know how to see if something is a part of something!
actuall problem:
I got a working system on if the blocks are a part of the vehicle. I dont know how to make the script know if it is not part of the vehicle anymore. Like, i move a block that is on the vehicle and the other blocks attached too it fall, but then it sees that it is touching the terrain and doesnt make it a part of the vehicle any more. But this is a problem because when i drive the vehicle, it thinks the parts are not part of the vehicle anymore.