How can I make my kart normal?

Hello developers! I am wondering how I can make my kart normal.

Screenshots:

image


Code:

local debounce = false
local FLCframe = script.Parent.Wheels.FL.CFrame
local FRCframe = script.Parent.Wheels.FR.CFrame
local RLCframe = script.Parent.Wheels.RL.CFrame
local RRCframe = script.Parent.Wheels.RR.CFrame


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 cl = script.Parent.DriveSeat.GiveGui.LoadCustom:Clone()
								cl.Parent = plr.PlayerGui
								local acc = found.BarStats.Acceleration
								local hand = found.BarStats.Handling
								local hp = found.BarStats.Horsepower
								local tp = found.BarStats.TopSpeed
								
								script.Parent.Stats.Handling.Value += hand.Value
								script.Parent.Stats.TopSpeed.Value += tp.Value
								script.Parent.Stats.Acceleration.Value += acc.Value
								script.Parent.Stats.Horsepower.Value += hp.Value
								
								wait(1)
								
								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
										weld.C0 = FRCframe
										weld.C1 = FRCframe
										cl.CFrame = FRCframe
										cl.Orientation = orentation - Vector3.new(0, 180, 0)

										cl.Anchored = false
										--cl.Parts:SetPrimaryPartCFrame(script.Parent.Wheels.FR.Parts.Rim.CFrame)
									end
								end
								script.Parent.Wheels.FR.Anchored = false
								--cl.Parts:SetPrimaryPartCFrame(script.Parent.Wheels.FR.Parts.Rim.CFrame)
							end

							--for _, v in pairs(fr.Parts:GetChildren()) do
							--	v.Orientation = script.Parent.Wheels.FR.Parts.Rim.Orientation
							--end
							--local childFR = script.Parent.Wheels.FR:GetDescendants()
							--childFR:Destroy()

							--fr.Name = "FR"
							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
									weld.C0 = FLCframe
									weld.C1 = FLCframe
									cl.CFrame = FLCframe
									cl.Orientation = orentation - Vector3.new(0, 180, 0)

									cl.Anchored = false
									--cl.Parts:SetPrimaryPartCFrame(script.Parent.Wheels.FR.Parts.Rim.CFrame)
								end
							end
							script.Parent.Wheels.FL.Anchored = false
							--for _, v in pairs(fl.Parts:GetChildren()) do
							--	v.Orientation = script.Parent.Wheels.FL.Parts.Rim.Orientation
							--end


							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
									weld.C0 = RLCframe
									weld.C1 = RLCframe
									cl.CFrame = RLCframe
									cl.Orientation = orentation

									cl.Anchored = false
									--cl.Parts:SetPrimaryPartCFrame(script.Parent.Wheels.FR.Parts.Rim.CFrame)
								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 = RRCframe
									cl.Orientation = orentation
									local weld = Instance.new("Weld", cl)
									weld.Part0 = cl
									weld.Part1 = script.Parent.Wheels.RR
									weld.C0 = RRCframe
									weld.C1 = RRCframe
									cl.Anchored = false
									cl.Orientation = orentation
									--cl.Parts:SetPrimaryPartCFrame(script.Parent.Wheels.FR.Parts.Rim.CFrame)
								end
							end
							script.Parent.Wheels.RR.Anchored = false

							-- Refresh
							wait()
							--script.Parent.DriveSeat:WaitForChild("SeatWeld"):Destroy()
							--print("Seat weld destroyed")
							--wait(0.1)
							--script.Parent.Start.Value = true
							debounce = true
							
							script.Parent.DriveSeat:WaitForChild("SeatWeld"):Destroy()
							local ws = human.WalkSpeed
							human.WalkSpeed = 0
							--script.Parent.DriveSeat:SetNetworkOwner(nil)
							wait(3)
							script.Parent.DriveSeat:Sit(human)
							human.WalkSpeed = ws
							--script.Parent.DriveSeat:SetNetworkOwner(plr)
							plr.PlayerGui.LoadCustom:Destroy()
							--script.Parent.DriveSeat:Sit(human)
						end
					end
				end
			end
		end
	end
end

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

Info

  • The scripts welds the tires to the kart. It used to work before, nothing changed
  • If I try using WeldConstraints, the kart breaks and the kart moves to where the tires are

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

1 Like