Need help with a car gui

So, recently i’ve made a car, and figured out how to control it through a gui, but now I don’t really know how can I make a speedometer on the same gui. Maybe a remote function would work? Thanks for help and sorry for my english.

3 Likes

A couple of questions to begin:

  • Is this a custom vehicle? (You made it, it’s not a pre-made chassis)
  • What type of GUI are we trying to create? Something that would display when the player is driving the vehicle?
  1. Yes it’s a custom made vehicle.
  2. We’re trying to do a custom speedometer when the player is driving a vehicle.
1 Like

To get you started on a basic speedometer, here is a quick showcase:

local Speedometer = script.Parent -- Location of speedometer
local CarName = "MyCarName" -- The name of the vehicle in the workspace (You probably already defined this)
local Car = workspace:FindFirstChild(CarName) -- Gets the vehicle from the workspace

local TS = game:GetService("TweenService")
local Info = TweenInfo.new(.05, Enum.EasingSyle.Sine, Enum.EasingDirection.InOut) -- Change however you would like to customize

local Units= {	
	{
		units = "MPH",
		scaling = (10/12) * (60/88), -- 1 stud : 10 inches | ft/s to MPH - Converts SPS to MPH
	},
	
	{
		units			= "KMH",
		scaling			= (10/12) * 1.09728, -- 1 stud : 10 inches | ft/s to KP/H - Converts SPS to KPH
	},
}

local CurrentUnit = 1

game:GetService("RunService").Heartbeat:Connect(function()
	TS:Create(Speedometer, Info, {Rotation = 255 * math.min(1, Units[CurrentUnit].scaling*Car.DriveSeat.Velocity.Magnitude/Car.DriveSeat.MaxSpeed)) 
-- Change the 255 at the start to how far the speedometer rotates when at full speed
end)

Let me know if you have any other questions

2 Likes

What if there are multiple cars in the workspace?

1 Like

If there are multiple cars in the workspace with the same name you could put this script inside the DriveSeat:

-- Regular Script

local DriveSeat = script.Parent

DriveSeat.ChildAdded:connect(function(Child)
    if Child.Name == "SeatWeld" and Child:IsA("Weld") and game.Players:GetPlayerFromCharacter(Child.Part1.Parent) ~= nil then
        local Player = game.Players:GetPlayerFromCharacter(Child.Part1.Parent)
        DriveSeat.Parent.Name = Player.UserId
    end
end)

Then, inside your speedometer script, you can change the location of your car to this:

-- Local Script

local Player = game.Players.LocalPlayer

repeat wait(.1) until workspace:FindFirstChild(Player.UserId) ~= nil

local Car = workspace:FindFirstChild(Player.UserId)

Let me know if this works or not.

1 Like

After some modifications it works perfectly! Thank you!

1 Like

Hello, the script doesn’t work for me I am using a local script and a frame for the speed needle, and it does not rotate at all.

1 Like

Are you sure that the DriveSeat and the Frame are defined correctly? Also, are you getting any errors?

EDIT: Inside of the script I forgot to make the Tween play. At the end of the line that begins with TS:Create() insert :Play() afterward. This should fix your issue

It worked thank you for the help!

1 Like

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