The tires are rotating weirdly

Hello developers! I hope you are having a great day!

I have a problem with tires rotating like this:
image
Whenever I go into the go-kart.

If I don’t use this script:

local debounce = false

function onChildAdded(hit)
	if debounce == false then
		local orentation = script.Parent.Wheels.RR.Parts.Rim.Orientation
		if hit.Name == "SeatWeld" then
			local human = hit.part1.Parent:FindFirstChild("Humanoid") 
			if (human ~= nil) then
				local plr = game.Players:GetPlayerFromCharacter(human.Parent)
				if plr then
					local kartFolder = plr:FindFirstChild("Kart")
					if kartFolder then
						local wheels = kartFolder:WaitForChild("Tires")
						local wheelsHolder = game.ReplicatedStorage.Tires
						local selected = nil
						for i, wheel in pairs(wheels:GetChildren()) do
							if wheel:IsA("BoolValue") then
								if wheel.Value == true then
									selected = wheel.Name
								end
							end
						end
						if selected ~= nil then
							local found = wheelsHolder:FindFirstChild(selected)
							if found then
								local fr = script.Parent.Wheels.FR
								for i, v in pairs(fr.Parts:GetDescendants()) do
									v:Destroy()
								end
								for i, ch in pairs(found:GetDescendants()) do
									if ch:IsA("BasePart") then
										local cl = ch:Clone()
										cl.Parent = script.Parent.Wheels.FR.Parts
										cl.Orientation = orentation
										local weld = Instance.new("Weld", cl)
										weld.Part0 = cl
										weld.Part1 = script.Parent.Wheels.FR
										cl.CFrame = script.Parent.Wheels.FR.CFrame

										cl.Anchored = false

									end
								end
								script.Parent.Wheels.FR.Anchored = false

							end

							local fl = script.Parent.Wheels.FR:Clone()
							for i, v in pairs(script.Parent.Wheels.FL.Parts:GetDescendants()) do
								v:Destroy()
							end
							for i, ch in pairs(found:GetDescendants()) do
								if ch:IsA("BasePart") then
									local cl = ch:Clone()
									cl.Parent = script.Parent.Wheels.FL.Parts
									cl.Orientation = orentation
									local weld = Instance.new("Weld", cl)
									weld.Part0 = cl
									weld.Part1 = script.Parent.Wheels.FL
									cl.CFrame = script.Parent.Wheels.FL.CFrame

									cl.Anchored = false
								end
							end
							script.Parent.Wheels.FL.Anchored = false
							local rl = script.Parent.Wheels.FR:Clone()
							for i, v in pairs(script.Parent.Wheels.RL.Parts:GetDescendants()) do
								v:Destroy()
							end
							for i, ch in pairs(found:GetDescendants()) do
								if ch:IsA("BasePart") then
									local cl = ch:Clone()
									cl.Parent = script.Parent.Wheels.RL.Parts
									cl.Orientation = orentation
									local weld = Instance.new("Weld", cl)
									weld.Part0 = cl
									weld.Part1 = script.Parent.Wheels.RL
									cl.CFrame = script.Parent.Wheels.RL.CFrame

									cl.Anchored = false
								end
							end
							script.Parent.Wheels.RL.Anchored = false

							local rr = script.Parent.Wheels.FL:Clone()
							for i, v in pairs(script.Parent.Wheels.RR.Parts:GetDescendants()) do
								v:Destroy()
							end
							for i, ch in pairs(found:GetDescendants()) do
								if ch:IsA("BasePart") then
									local cl = ch:Clone()
									cl.Parent = script.Parent.Wheels.RR.Parts

									cl.CFrame = script.Parent.Wheels.RR.CFrame
									cl.Orientation = orentation
									local weld = Instance.new("Weld", cl)
									weld.Part0 = cl
									weld.Part1 = script.Parent.Wheels.RR
									cl.Anchored = false
								end
							end
							script.Parent.Wheels.RR.Anchored = false
						end
					end
				end
			end
		end
	end
end

script.Parent.DriveSeat.ChildAdded:Connect(onChildAdded)

The tires are just normal:
image

Solutions I tried:

  • I tried matching the Orientation on all the parts, matching them on the normal kart
  • I tried setting the oreintation in the script before and after the welding operation
  • I used WeldConstraints, which break the kart

If you can help, please let me know. Thank you, WE

Solution 1: You can manually set the orientation of the wheels using Weld.C0/Weld.C1 (ref).
Solution 2: Just use WeldConstraints.

How would I use Weld.CO and Weld.C1? Could you provide an example please?

Let’s take a look, here we have two transparent parts. What I want to do is weld the red part on top of the green part. I will also keep the green part anchored since the red one will be welded to it.:
Capture.PNG


Here is a simple script that I made to make that possible.
local Green = workspace.Green
local Red = workspace.Red

local Weld = Instance.new("ManualWeld")
Weld.Part0 = Red
Weld.Part1 = Green
Weld.Parent = Red

Now if we run the game and observe what happens:

Capture.PNG


We can see that the red part weded to the green part but not in the position we wanted. So in order to make the red part maintain its position, I'm gonna add a line to my code:
local Green = workspace.Green
local Red = workspace.Red

local Weld = Instance.new("ManualWeld")
Weld.Part0 = Red
Weld.Part1 = Green
Weld.Parent = Red

Weld.C0 = CFrame.new(0, -Green.Size.Y, 0) --Added

Now it works as expected!

Capture.PNG

1 Like

Fixed by setting the orientation after the weld.