Need help adding different pitch effects while the car is speeding up?

So I have this improved Jeep here. It works fine. It drives properly. It accelerates properly. Now the pitching of the engine sound is fine but now what I am trying to do: https://streamable.com/e5q2am

As you can see in the vidfeo, you can see my driving the car normally as always. What you notice about the engine sound is the PlaybackSpeed. Yes it pitches properly. Not I want it to have different pitches. For example, when I get faster meaning I am on the second gear, the engine sound will go back to lower pitch then pitch up again. Then shift into 3rd gear, it will do the same thing. When it shifts to another gear, it will just do the same thing over and over again.

The Car Script (Server Side):

--Scripted by DermonDarble
local Gears = {
	Gear1 = "FirstGear",
	Gear2 = "SecondGear",
	Gear3 = "ThirdGear",
	Gear4 = "FourthGear"
}

local CurrentGear = nil
local ratio

local car = script.Parent
local stats = car.Configurations
local Raycast = require(script.RaycastModule)

local mass = 0

for i, v in pairs(car:GetChildren()) do
	if v:IsA("BasePart") then
		mass = mass + (v:GetMass() * 196.2)
	end
end

local bodyPosition = car.Chassis.BodyPosition
local bodyGyro = car.Chassis.BodyGyro

--local bodyPosition = Instance.new("BodyPosition", car.Chassis)
--bodyPosition.MaxForce = Vector3.new()
--local bodyGyro = Instance.new("BodyGyro", car.Chassis)
--bodyGyro.MaxTorque = Vector3.new()

stats.Throttle:GetPropertyChangedSignal("Value"):Connect(function()
	if stats.Throttle.Value == true then
		while stats.Throttle.Value == true do
			wait()
			stats.Speed.Value = stats.Speed.Value + 1
			if not stats.Throttle.Value == true then
				print("Broke Loop")
				break
			end
		end
	end
	if stats.Throttle.Value == false then
		while stats.Speed.Value > 0 do
			wait()
			stats.Speed.Value = stats.Speed.Value - 1
			if stats.Speed.Value == 1 then
				stats.Speed.Value = 0
				print("STOP LOOP")
				break
			end
			if stats.Reverse.Value == true then
				print("cancel forward")
				break
			end
		end
	end
end)

stats.Reverse:GetPropertyChangedSignal("Value"):Connect(function()
	if stats.Reverse.Value == true then
		stats.Speed.Value = 0
		while stats.Reverse.Value == true do
			wait()
			stats.Speed.Value = stats.Speed.Value + 1
			if not stats.Reverse.Value == true then
				print("Broke Reverse Loop")
				break
			end
		end
	end
	if stats.Reverse.Value == false then
		while stats.Speed.Value > 0 do
			wait()
			stats.Speed.Value = stats.Speed.Value - 1
			if stats.Speed.Value == 1 then
				stats.Speed.Value = 0
				print("STOP LOOP")
				break
			end
			if stats.Throttle.Value == true then
				print("cancel reverse")
				break
			end
		end
	end
end)

local function UpdateThruster(thruster)
	-- Raycasting
	local hit, position = Raycast.new(thruster.Position, thruster.CFrame:vectorToWorldSpace(Vector3.new(0, -1, 0)) * stats.Height.Value) --game.Workspace:FindPartOnRay(ray, car)
	local thrusterHeight = (position - thruster.Position).magnitude
	
	-- Wheel
	local wheelWeld = thruster:FindFirstChild("WheelWeld")
	wheelWeld.C0 = CFrame.new(0, -math.min(thrusterHeight, stats.Height.Value * 0.8) + (wheelWeld.Part1.Size.Y / 2), 0)
	-- Wheel turning
	local offset = car.Chassis.CFrame:inverse() * thruster.CFrame
	local speed = car.Chassis.CFrame:vectorToObjectSpace(car.Chassis.Velocity)
	if offset.Z < 0 then
		local direction = 1
		if speed.Z > 0 then
			direction = -1
		end
		wheelWeld.C0 = wheelWeld.C0 * CFrame.Angles(0, (car.Chassis.RotVelocity.Y / 2) * direction, 0)
	end
	
	-- Particles
	--[[if hit and thruster.Velocity.magnitude >= 5 then
		wheelWeld.Part1.ParticleEmitter.Enabled = true
	else
		wheelWeld.Part1.ParticleEmitter.Enabled = false
	end]]
end

car.DriveSeat.Changed:connect(function(property)
	if property == "Occupant" then
		if car.DriveSeat.Occupant then
			local player = game.Players:GetPlayerFromCharacter(car.DriveSeat.Occupant.Parent)
			if player then
				car.DriveSeat:SetNetworkOwner(player)
				car.EngineBlock.Enter:Play()
				car.EngineBlock.Enter.Ended:Wait()
				car.EngineBlock.Start:Play()
				car.EngineBlock.Running:Play()
				local localCarScript = script.LocalCarScript:Clone()
				localCarScript.Parent = player.PlayerGui
				localCarScript.Car.Value = car
				localCarScript.Disabled = false
			end
		else
			car.EngineBlock.Running:Stop()
			car.EngineBlock.Enter:Play()
			car.EngineBlock.Enter.Ended:Wait()	
			car.EngineBlock.Lock:Play()		
		end
	end
	if car.DriveSeat.Throttle == 1 then
		--print("Throttle On")
		stats.Throttle.Value = true
	else
		--print("Throttle Off")
		stats.Throttle.Value = false
	end
	if car.DriveSeat.Throttle == -1 then
		stats.Reverse.Value = true
	else
		stats.Reverse.Value = false
	end
end)

--spawn(function()
	while true do
		game:GetService("RunService").Stepped:wait()
		for i, part in pairs(car:GetChildren()) do
			if part.Name == "Thruster" then
				UpdateThruster(part)
			end
		end
		if car.DriveSeat.Occupant and car.DriveSeat.Velocity.Magnitude > 0 then
		--local ratio = car.DriveSeat.Velocity.magnitude / stats.Speed.Value
		ratio = car.DriveSeat.Velocity.Magnitude / 140, math.min(60 * 5, 1)
			car.EngineBlock.Running.PlaybackSpeed = 1 + ratio * 5
			car.EngineBlock.Running.Volume = 0.3 + ratio
			bodyPosition.MaxForce = Vector3.new()
			bodyGyro.MaxTorque = Vector3.new()
		else
			local hit, position, normal = Raycast.new(car.Chassis.Position, car.Chassis.CFrame:vectorToWorldSpace(Vector3.new(0, -1, 0)) * stats.Height.Value)
			if hit and hit.CanCollide then
				bodyPosition.MaxForce = Vector3.new(mass / 5, math.huge, mass / 5)
				bodyPosition.Position = (CFrame.new(position, position + normal) * CFrame.new(0, 0, -stats.Height.Value + 0.5)).p
				bodyGyro.MaxTorque = Vector3.new(math.huge, 0, math.huge)
				bodyGyro.CFrame = CFrame.new(position, position + normal) * CFrame.Angles(-math.pi/2, 0, 0)
			else
				bodyPosition.MaxForce = Vector3.new()
				bodyGyro.MaxTorque = Vector3.new()
			end
		end
	end
--end)

That came from the Jeep cause I just said earlier, It’s an improved Jeep. Better driving and acceleration. Now , if you have any ideas, suggestions, want something to add to the code that will help fix the problem, just reply below!

Let me know all down in the replies below. All help is appreciated.

Contact me in discord: Well…HERE WE GO AGAIN#8679 and tell me your discord username when adding me in discord. Cause I have a lot of random people adding me. If you want to get access to the Jeep to help fix the problem, just add that account right there. And you will get in contact with me.

1 Like

Oh well. I just found a solution to the problem lol. After messing around for hours now it finally matched my needs:

That’s what I did:

stats.Speed.Changed:Connect(function()
	if stats.Speed.Value == 60 then
		stats.Gear.Value = "Second"	
	end
	if stats.Speed.Value == 130 then
		stats.Gear.Value = "Third"	
	end
	if stats.Speed.Value == 190 then
		stats.Gear.Value = "Fourth"	
	end
end)

https://streamable.com/e5q2am the results