Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Turning objects with .C1 weld - CFrame.Angles?

Asked by
Mowblow 117
8 years ago

I am currently attempting to make a car that when the .Steer values of a vehicle seat are 0,1, or -1, the wheels turn. However, the wheels are not turning, and I am not sure why.

Below are the two scripts I am using to one, generate the weld, and two, control them.

Weld:

local prev
local parts = script.Parent:GetChildren()
for i = 1,#parts do
    if ((parts[i].className == "Part") or (parts[i].className == "Seat") or (parts[i].className == "WedgePart") or (parts[i].className == "Seat") or (parts[i].className == "TrussPart") or (parts[i].className == "VehicleSeat") or (parts[i].className == "SkateboardPlatform")) then
        if (prev ~= nil) then
            if (parts[i].Name == "FLWheel") or (parts[i].Name == "FRWheel") then
                local weld = Instance.new("Weld")
                weld.Part0 = script.Parent.Engine
                weld.Part1 = parts[i]
                weld.C0 = script.Parent.Engine.CFrame:inverse()
                weld.C1 = parts[i].CFrame:inverse()
                weld.Parent = parts[i]
                parts[i].Anchored = false
                weld.Name = "WheelWeld"

            else
                local weld = Instance.new("Weld")
                weld.Part0 = prev
                weld.Part1 = parts[i]
                weld.C0 = prev.CFrame:inverse()
                weld.C1 = parts[i].CFrame:inverse()
                weld.Parent = prev
                parts[i].Anchored = false

            end 

        end
        if (parts[i].Name == "FLWheel") or (parts[i].Name == "FRWheel") then
            prev = prev
        else 
            prev = parts[i] 
        end 
    end
end
wait(3)

Main Driving Script:



--Editting properties: local TurnSpeed = nil local MaximumSpeed = nil local SetSpeed = nil local Braking = nil local Car = script.Parent.Parent local Seat = script.Parent local Driving = false script.Parent.ChildAdded:connect(function(child) if child.Name == "SeatWeld" and child:IsA("Weld") then Driving = true local character = child.Part1.Parent local player = game.Players:GetPlayerFromCharacter(character) Car.CarOwner.Value = player.Name end end) script.Parent.ChildRemoved:connect(function(child) if child.Name == "SeatWeld" then Driving = false end end) MainDrive = coroutine.create(function() end) local FRWeld = Car.FRWheel:WaitForChild("WheelWeld") local FLWeld = Car.FLWheel:WaitForChild("WheelWeld") local welds = {FLWeld.C1,FRWeld.C1} LeftRightWheel = coroutine.create(function() while wait() do if Driving == true then if Seat.Steer == -1 then welds[1] = welds[1] * CFrame.Angles(0,90,0) welds[2] = welds[2] * CFrame.Angles(0,-90,0) elseif Seat.Steer == 1 then welds[1] = welds[1] * CFrame.Angles(0,-90,0) welds[2] = welds[2] * CFrame.Angles(0,90,0) elseif Seat.Steer == 0 then welds[1] = welds[1] * CFrame.Angles(0,0,0) welds[2] = welds[2] * CFrame.Angles(0,0,0) end end end end) coroutine.resume(LeftRightWheel)

All of the variables are correctly defined, and the instance "WheelWeld" has a part0 of the center part in the car, "Engine" and a Part1 of the wheel. The if statement for the main drive script is passing, I checked with "print()". I can't tell why it isn't turning....

Am I trying to rotate them incorrectly?

Answer this question