Car Speed is glitching

  1. What do you want to achieve? Keep it simple and clear!
  • I want to get the actual speed of my car but it is glitching and never stopping.
  1. What is the issue? Include screenshots / videos if possible!

  2. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

  • Yeah, as always, none was my solution.

////////////////////////////////////////////////////////////////

Here’s the code.

local speed = math.floor(seatPart.CFrame.LookVector:Dot(seatPart.AssemblyLinearVelocity))
repeat wait()
	if script.Parent.Parent.Unit.Value == "mph" then
		script.Parent.Text = speed .."<font size='4'>"..script.Parent.Parent.Unit.Value.."</font>"
	end	
until seatPart.Occupant == nil
4 Likes
local speed = math.floor(seatPart.AssemblyLinearVelocity.Magnitude)
repeat wait()
	if script.Parent.Parent.Unit.Value == "mph" then
		script.Parent.Text = speed .."<font size='4'>"..script.Parent.Parent.Unit.Value.."</font>"
	end	
until seatPart.Occupant == nil
1 Like

Still doesn’t work, at this point it doesn’t even stop and it just displays “11”,“19” and more random numbers.

1 Like

May I see the full script?

_

2 Likes
local character = game.Players.LocalPlayer.Character

local function getAverageVelocity(motorFR, motorBR, motorFL, motorBL, base)
	local vFR = -motorFR.WorldAxis:Dot(base.RotVelocity)
	local vRR = -motorBR.WorldAxis:Dot(base.RotVelocity)
	local vFL = motorFL.WorldAxis:Dot(base.RotVelocity)
	local vRL = motorBL.WorldAxis:Dot(base.RotVelocity)
	return 0.25 * ( vFR + vFL + vRR + vRL )
end

script.Parent.Parent.ChangeSpeed.MouseButton1Click:Connect(function()
	if script.Parent.Parent.Unit.Value == "mph" then
		script.Parent.Parent.Unit.Value = "kmh"
	elseif script.Parent.Parent.Unit.Value == "kmh" then
		script.Parent.Parent.Unit.Value = "mph"
	end
end)

character.Humanoid.Seated:Connect(function(active, seatPart)
	if seatPart.Name ~= "VehicleSeat" then return end

	seatPart.Changed:Connect(function(property)
		--local speed = getAverageVelocity(seatPart.Parent.Base.AttachmentFR, seatPart.Parent.Base.AttachmentBR, seatPart.Parent.Base.AttachmentFL, seatPart.Parent.Base.AttachmentBL, seatPart)
		local speed = math.floor(seatPart.AssemblyLinearVelocity.Magnitude)
		repeat wait()
			if script.Parent.Parent.Unit.Value == "mph" then
				script.Parent.Text = speed .."<font size='4'>"..script.Parent.Parent.Unit.Value.."</font>"
			end	
		until seatPart.Occupant == nil
			
			--[[if speed > 5 then
				seatPart.Audio.Engine.Playing = true
				seatPart.Audio.Engine.Looped = true
				seatPart.Audio.Idle.Playing = false
				seatPart.Audio.Idle.Looped = false
				seatPart.Audio.Idle.TimePosition = math.huge
				seatPart.Audio.Engine.Ended:Wait()
			else
				seatPart.Audio.Engine.Playing = false
				seatPart.Audio.Engine.Looped = false
				seatPart.Audio.Engine.TimePosition = math.huge
				seatPart.Audio.Idle.Playing = true
				seatPart.Audio.Idle.Looped = true
				seatPart.Audio.Idle.Ended:Wait()
			end]]
	end)
end)	
local character = game.Players.LocalPlayer.Character

local function getAverageVelocity(motorFR, motorBR, motorFL, motorBL, base)
	local vFR = -motorFR.WorldAxis:Dot(base.RotVelocity)
	local vRR = -motorBR.WorldAxis:Dot(base.RotVelocity)
	local vFL = motorFL.WorldAxis:Dot(base.RotVelocity)
	local vRL = motorBL.WorldAxis:Dot(base.RotVelocity)
	return 0.25 * ( vFR + vFL + vRR + vRL )
end

script.Parent.Parent.ChangeSpeed.MouseButton1Click:Connect(function()
	if script.Parent.Parent.Unit.Value == "mph" then
		script.Parent.Parent.Unit.Value = "kmh"
	elseif script.Parent.Parent.Unit.Value == "kmh" then
		script.Parent.Parent.Unit.Value = "mph"
	end
end)

character.Humanoid.Seated:Connect(function(active, seatPart)
	if seatPart.Name ~= "VehicleSeat" then return end
	if active then return end

	--local speed = getAverageVelocity(seatPart.Parent.Base.AttachmentFR, seatPart.Parent.Base.AttachmentBR, seatPart.Parent.Base.AttachmentFL, seatPart.Parent.Base.AttachmentBL, seatPart)
	repeat task.wait()
		local speed = math.floor(seatPart.AssemblyLinearVelocity.Magnitude)
		if script.Parent.Parent.Unit.Value == "mph" then
			script.Parent.Text = speed .."<font size='4'>"..script.Parent.Parent.Unit.Value.."</font>"
		end	
	until seatPart.Occupant == nil

			--[[if speed > 5 then
				seatPart.Audio.Engine.Playing = true
				seatPart.Audio.Engine.Looped = true
				seatPart.Audio.Idle.Playing = false
				seatPart.Audio.Idle.Looped = false
				seatPart.Audio.Idle.TimePosition = math.huge
				seatPart.Audio.Engine.Ended:Wait()
			else
				seatPart.Audio.Engine.Playing = false
				seatPart.Audio.Engine.Looped = false
				seatPart.Audio.Engine.TimePosition = math.huge
				seatPart.Audio.Idle.Playing = true
				seatPart.Audio.Idle.Looped = true
				seatPart.Audio.Idle.Ended:Wait()
			end]]
end)
1 Like

Dude thank you so much it worked!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.