Union wheel not working for car

I wanted to remake the “Wheel Drawing Obby” game where you can make your own wheel for your car.

I added the drawing script, and made a script to make the wheel and position it to the wheel.
But the wheel doesnt work.
I put all of the hinges, attachments, etc in the right place.
But the wheel just doesnt spin.

I believe the problem is I unioned the wheel and unions dont have proper collision, making the wheels not work.

I was thinking of welding all of the wheel parts together, and then make them the wheel instead of relyiing on unions.
But I didnt try that since i figured i cant attach the welded wheels to the hinge.

How would i go on to achieve this?

If you were to weld all the parts, you could weld them all to one part that is attached to the hinge

1 Like

yeah good point but i was like doing that a few hours ago got 1 wheel done and it looked like the wheel wasnt rotation.
Would u have any idea to how to make all the wheels instantly with a loop or something?
im doing it manually for every wheel

Could you show me the drawing script?

drawing script or the wheel creation one (theyre seperate)

I think if i saw the drawing script it would be easier to help you out

local replicatedStorage = game:GetService('ReplicatedStorage')





local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hrp = character:WaitForChild("HumanoidRootPart")
local camera = workspace.CurrentCamera

local frame = script.Parent
local finishButton = frame.Parent.FinishButton

local dragging = false
local drawingData = {}
local Draw_Cool_Down = false


local params = RaycastParams.new()
params.FilterDescendantsInstances = {} 
params.FilterType = Enum.RaycastFilterType.Blacklist 


local function instanceParts(pos)
	local part = Instance.new("Part", workspace)
	part.Shape = Enum.PartType.Ball
	part.Position = pos
	part.Size = Vector3.new(1,1,1)
	part.Anchored = true
	part.BrickColor = BrickColor.Red()
end


local function finsihDrawing()
	for i,v in drawingData do
		instanceParts(v)
	end
end


local function DrawAt(x, y)
	local playerCar = player.PlayerCar.Value
	local topLeft = frame.AbsolutePosition

	local point = Instance.new("Frame")
	point.Size = UDim2.fromOffset(25, 25)
	point.BackgroundColor = BrickColor.Red()
	
	point.Position = UDim2.fromOffset(x - topLeft.X - 12.5, y - topLeft.Y - 12.5)
	point.Parent = frame
	table.insert(drawingData, (Vector3.new(point.Position.X.Offset/35, point.Position.Y.Offset/35, -20) + playerCar:WaitForChild("backWheel1").Position))
	
end



frame.InputChanged:Connect(function(input)
	if Draw_Cool_Down == true then 
		return
	end
	Draw_Cool_Down= true 
	if dragging and input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
		DrawAt(input.Position.X, input.Position.Y)
	end
	task.wait(0.05)
	Draw_Cool_Down = false
end)





finishButton.MouseButton1Click:Connect(function()
	replicatedStorage.DrawingFinish:FireServer(drawingData)
end)





frame.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
		dragging = true
	end
end)


frame.InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
		dragging = false
	end
end)

I got most of the math code from some dev forum

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