Help with scripting a car GUI

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I’m trying to build a player screen GUI for my car chassis.

  2. What is the issue? I’ve pre-built the GUI, but I just can’t get the speedometer to report the correct speed. It just says 0. image

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I did, but I couldn’t find any solutions related to speed reporting. I tried referencing the current Target Speed, the current HingeConstraint Angular Velocity, etc… but I just can’t seem to be able to reference the Hinges or Values from the PlayerGUI.

Here’s my VehicleSeat so far:
image

The motors:
image

My current script:

local seat = script.Parent
local guiName = "GUI"
local gui = script:WaitForChild("GUI")
local Players = game:GetService("Players")
local lastplr 

-- each time the Occupant property of the seat fires...
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if seat.Occupant ~= nil then
		local char = seat.Occupant.Parent
		local player = Players:GetPlayerFromCharacter(char)
		local cloned = gui:Clone()
		cloned.Parent = player.PlayerGui
		lastplr = {player, cloned} -- store player and Gui in array
	else
		print("player left")
		if lastplr then -- verify lastplayer is not nil
			lastplr[2]:Destroy() -- since the table's numerically indexed, we know lastplr[2] will be the Gui
			lastplr = nil
		end
	end
end)

What it looks like when I play:
image

The script that I want to change the text with:

while true do
wait()
     script.Parent.Text = script.Parent.Parent.Parent.Parent.Parent.Speed.Value
end

And the error it throws:
image

If anyone can help me, it would be appreciated.

I believe you are definine your variables Inncorrecly,

script.Parent--Returns the Parent of the Script

I assume the Car is a descendant of the workspace as it cannot exist in the PlayerService.
What It should be similar to:

workspace.Car.Speed.Value
1 Like

What I’m thinking is that if there are multiple cars with the same name, this won’t work.
And which variable am I defining wrongly?

I never read your post Correctly.
I recommend changing your gui from the Client. The client would read the speed of the car from the server and display it.
Example

local Speed = workspace[CarName].Speed--Defines Speed
local Gui = script.Parent--Defines Gui

Speed.Changed:Connect(function()--Event Which triggers when the value of speed changes
Gui.SpeedLabel.Text = Speed.Value--changes the text of the label to match the current speed
end)

For a CustomCar Name:
I recommend making the Car Name, the players name, Car. → “BuildersmanCar”

--To set the car Name
local Car.Name = (Player.Name.."Car")->"BuiderMansCar"

--Reading CarName
workspace[Player.Name.."Car"]-> workspace.BuildersManCar
3 Likes

Huh, is this what you were talking about?
image
It errors:
image
Could you tell me how to fix it?