local replicatedStorage = game:GetService('ReplicatedStorage')
local function Instance_Parts(pos, wheel)
local part = Instance.new("Part", workspace)
part.Shape = Enum.PartType.Ball
part.Position = Vector3.new(pos.X, pos.Y, 0) + wheel.Position
part.Size = Vector3.new(1,1,1)
part.Anchored = true
part.BrickColor = BrickColor.Red()
return part
end
local function PlaceHolder(object, player)
local playerCar = player.PlayerCar.Value
local back_Wheel1 = playerCar:WaitForChild("backWheel1")
local back_WheelCFrame = back_Wheel1.CFrame
print('Creating wheel..')
local wheel = back_Wheel1:UnionAsync(object)
print('Finished making wheel')
playerCar:MoveTo(Vector3.new(0,100,0))
wheel.Parent = playerCar
wheel.CFrame = back_WheelCFrame
back_Wheel1:Destroy()
for i,v in object do
v:Destroy()
end
wheel.Anchored = false
local Wheel_Hinge = playerCar.RightWheel2
local Attachment_0 = Instance.new("Attachment", playerCar.BackWheel1Holder)
local Attachment_1 = Instance.new("Attachment" , wheel)
Attachment_0.Position = Vector3.new(0.5,0,0)
Attachment_1.Position = Vector3.new(-0.5, 0,0)
Wheel_Hinge.Attachment0 = Attachment_0
Wheel_Hinge.Attachment1 = Attachment_1
end
local function smallOperations(Player_Car, OperationType)
for i,v in Player_Car:GetChildren() do
if v:IsA("Part") or v:IsA("UnionOperation")then
if OperationType == "Anchor" then
v.Anchored = true
elseif OperationType == "UnAnchor" then
v.Anchored = false
end
end
end
end
local function Create_Wheel(Player_Car, object)
local backWheel_1 = {}
local frontWheel_1 ={}
local frontWheel_2 = {}
for i,v in object do
table.insert(backWheel_1, v:Clone())
table.insert(frontWheel_2, v:Clone())
table.insert(frontWheel_1, v:Clone())
end
print(frontWheel_2)
local function Create_Weld()
for i,v in object do
local weld = Instance.new("WeldConstraint", v)
weld.Part0 = v
weld.Part1 = Player_Car.backWheel2
end
for i,v in backWheel_1 do
local weld = Instance.new("WeldConstraint", v)
weld.Part0 = v
weld.Part1 = Player_Car.backWheel1
end
for i,v in frontWheel_1 do
local weld = Instance.new("WeldConstraint", v)
weld.Part0 = v
weld.Part1 = Player_Car.frontWheel1
end
for i,v in frontWheel_2 do
local weld = Instance.new("WeldConstraint", v)
weld.Part0 = v
weld.Part1 = Player_Car.frontWheel2
end
end
-- Variable
smallOperations(Player_Car, "Anchor")
Player_Car:PivotTo(CFrame.new(Vector3.new(0,10,0)))
local CFrameForUnion = Player_Car["backWheel2"].CFrame
local ModelToCenterWheel = Instance.new("Model", workspace)
for i,v in object do v.Parent = ModelToCenterWheel end
ModelToCenterWheel:PivotTo(CFrameForUnion * CFrame.Angles(0, math.rad(90), 0))
for i,v in object do v.Parent = Player_Car end
CFrameForUnion = Player_Car["backWheel1"].CFrame
for i,v in backWheel_1 do v.Parent = ModelToCenterWheel end
ModelToCenterWheel:PivotTo(CFrameForUnion * CFrame.Angles(0, math.rad(90), 0))
for i,v in object do v.Parent = Player_Car end
CFrameForUnion = Player_Car["frontWheel1"].CFrame
for i,v in frontWheel_1 do v.Parent = ModelToCenterWheel end
ModelToCenterWheel:PivotTo(CFrameForUnion * CFrame.Angles(0, math.rad(90), 0))
for i,v in object do v.Parent = Player_Car end
CFrameForUnion = Player_Car["frontWheel2"].CFrame
for i,v in frontWheel_2 do v.Parent = ModelToCenterWheel end
ModelToCenterWheel:PivotTo(CFrameForUnion * CFrame.Angles(0, math.rad(90), 0))
for i,v in object do v.Parent = Player_Car end
ModelToCenterWheel:Destroy()
Create_Weld(Player_Car.backWheel1)
smallOperations(Player_Car, "UnAnchor")
end
replicatedStorage.DrawingFinish.OnServerEvent:Connect(function(player, drawingData)
local playerCar = player.PlayerCar.Value
local back_Wheel1 = playerCar:WaitForChild("backWheel1")
local object = {}
for i,v in drawingData do table.insert(object, Instance_Parts(v, back_Wheel1)) end
Create_Wheel(playerCar, object)
end)
sorry for the spaghetti code, i tried my best to make it clean