Hello! I hope you are all having an amazing day! I have a little problem.
If I were to change the karts tires manually, without the script, it would just drive normally as seen in the picture:
However, we use Players data to change the karts look and it does this:
Here is the script used to change the kart (Simply click here)
local debounce = false
function onChildAdded(hit)
if debounce == false then
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 = found:Clone()
fr.Parent = script.Parent.Wheels
fr.Parts:SetPrimaryPartCFrame(script.Parent.Wheels.FR.CFrame)
for _, v in pairs(fr.Parts:GetChildren()) do
v.Orientation = script.Parent.Wheels.FR.Parts.Rim.Orientation
end
script.Parent.Wheels.FR:Destroy()
fr.Name = "FR"
local fl = fr:Clone()
fl.Parent = script.Parent.Wheels
fl.Parts:SetPrimaryPartCFrame(script.Parent.Wheels.FL.CFrame)
for _, v in pairs(fl.Parts:GetChildren()) do
v.Orientation = script.Parent.Wheels.FL.Parts.Rim.Orientation
end
script.Parent.Wheels.FL:Destroy()
fl.Name = "FL"
local rl = fr:Clone()
rl.Parent = script.Parent.Wheels
rl.Parts:SetPrimaryPartCFrame(script.Parent.Wheels.RL.CFrame)
for _, v in pairs(rl.Parts:GetChildren()) do
v.Orientation = script.Parent.Wheels.RL.Parts.Rim.Orientation
end
script.Parent.Wheels.RL:Destroy()
rl.Name = "RL"
local rr = fr:Clone()
rr.Parent = script.Parent.Wheels
rr.Parts:SetPrimaryPartCFrame(script.Parent.Wheels.RR.CFrame)
for _, v in pairs(rr.Parts:GetChildren()) do
v.Orientation = script.Parent.Wheels.RR.Parts.Rim.Orientation
end
script.Parent.Wheels.RR:Destroy()
rr.Name = "RR"
wait(0.3)
script.Parent.DriveSeat:WaitForChild("SeatWeld"):Destroy()
print("Seat weld destroyed")
wait(0.1)
script.Parent.Start.Value = true
debounce = true
wait(2.6)
script.Parent.DriveSeat:Sit(human)
end
end
end
end
end
end
end
end
script.Parent.DriveSeat.ChildAdded:Connect(onChildAdded)
Info:
- The karts use A-Chassis, and we added
repeat wait() until script.Parent.Start.Value == true
to the A-Chassis Tuning script. - Changing the engine and body work completely fine as seen in this script:
Click here for the script
local debounce = false
function onChildAdded(hit)
if debounce == false then
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("Bodies")
local wheelsHolder = game.ReplicatedStorage.Bodies
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
script.Parent.Body["Kart Body"].FRAME:Destroy()
script.Parent.Body["Kart Body"].Color:Destroy()
for i, ch in pairs(found:GetChildren()) do
if ch:IsA("BasePart") then
local cl = ch:Clone()
cl.Parent = script.Parent.Body["Kart Body"]
cl.Orientation = Vector3.new(0, script.Parent.Body["Kart Body"].Floor.Orientation.Y * -1, 0)
cl.Position = script.Parent.Body["Kart Body"].Floor.Position + Vector3.new(-2.183, 0.835, -0.095)
end
end
wait(0.3)
script.Parent.DriveSeat:WaitForChild("SeatWeld"):Destroy()
print("Seat weld destroyed")
end
end
local wheels = kartFolder:WaitForChild("Engines")
local wheelsHolder = game.ReplicatedStorage.Engines
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 oldEng = script.Parent.Body["Power Box"]
print("ENG START")
--[[if found:FindFirstChild("Offset") then
offset = CFrame.new(found:FindFirstChild("Offset").Value)
else
offset = CFrame.new(-2.299, 0.462, 0.571)
end]]--
local cl = found:Clone()
cl.Parent = script.Parent.Body
cl.Name = "Power Box1"
cl:SetPrimaryPartCFrame(script.Parent.Body["Power Box"].Engine.CFrame)
script.Parent.Body["Power Box"]:Destroy()
cl.Name = "Power Box"
end
end
wait(0.5)
print("BODY START")
script.Parent.Start.Value = true
debounce = true
wait(2.6)
script.Parent.DriveSeat:Sit(human)
end
end
end
end
end
end
script.Parent.DriveSeat.ChildAdded:Connect(onChildAdded)
(The default engine is the one seen in the picture above)
If you can help, please let me know. Thanks, BrainDead_Dev and WEcompany