Creating a speed detector

Hihi, I’m quite new to scripting, I encounter many scripting issues but I always experiment it myself or asking a friend of mine who is a scripter.

I am currently trying to make a system that detects the speed of a vehicle that uses A-chassis. If the vehicle exceeded a certain speed, the system will give a warning sound and a icon will lit up.

The issue I’m facing right now is that I am unable to make the system detect the speed of the vehicle despite trying a few methods such as directly getting the speed from the GUI gauges which did not work. I’ve looked through DevForum where they said to use the Velocity of the vehicle or to use RayCast. However I could not reinterpret it into a script format as I have very less scripting experience. I’ve also tried asking my friend but he did not seem to understand it as well. I’ve already made part of the system like the warning sound and the lighting up of icon but it’s just the top part that is not working.

EDIT: [This system is in the vehicle and it’s part of the vehicle body.]

The script below is the current one I have now.

while true do
    script.Parent.Value.Value = script.Parent.Parent.Parent["A-Chassis Tune"]["A-Chassis Interface"].AC6_Stock.Gauges.Speed.Text
    if script.Parent.Value.Value >= 30 then
        script.Parent.Speeding.BrickColor = BrickColor.new(134, 189, 71)
        script.Parent.Speeding.Material = "Neon"
        script.Parent.Speeding.Transparency = 0.5
        script.Parent.Sound.Beep:Play()
        wait(5)    
        script.Parent.Speeding.BrickColor = BrickColor.new(17, 17, 17)
        script.Parent.Speeding.Material = "SmoothPlastic"
        script.Parent.Speeding.Transparency = 0    
    else
        script.Parent.Speeding.BrickColor = BrickColor.new(17, 17, 17)
        script.Parent.Speeding.Material = "SmoothPlastic"
        script.Parent.Speeding.Transparency = 0
    end 
end

Use the car model’s PrimaryPart velocity.

CarModel.PrimaryPart.AssemblyLinearVelocity
1 Like

This is the script I’ve amendment. I have tried it but it didn’t seem to work. Did I miss out anything?

while true do
	if script.Parent.Parent.Parent.Parent["Man A22 Euro 5 Batch 1/2 Stripe"].PrimaryPart.AssemblyLinearVelocity + Vector3(0, 0, 30) then
		script.Parent.Speeding.BrickColor = BrickColor.new(134, 189, 71)
		script.Parent.Speeding.Material = "Neon"
		script.Parent.Speeding.Transparency = 0.5
		script.Parent.Sound.Beep:Play()
		wait(5)	
		script.Parent.Speeding.BrickColor = BrickColor.new(17, 17, 17)
		script.Parent.Speeding.Material = "SmoothPlastic"
		script.Parent.Speeding.Transparency = 0	
	else
		script.Parent.Speeding.BrickColor = BrickColor.new(17, 17, 17)
		script.Parent.Speeding.Material = "SmoothPlastic"
		script.Parent.Speeding.Transparency = 0
	end 
end

is incorrect
if script.Parent.Parent.Parent.Parent["Man A22 Euro 5 Batch 1/2 Stripe"].PrimaryPart.AssemblyLinearVelocity.Z > 30 then

Hm doesn’t seem to work despite the changes. I believe maybe I’m missing out the WaitForChild part or am I wrong?

Check your code again, make sure that everything’s correct.

Without seeing your model hierarchy I can’t really help you further.

Hm, I did multiple checks on the script and it did not seem to have any problem but since you’ll like to have look at the model hierarchy, I’ve taken some screenshot that might be relevant to this issue and might help.

The first picture is the whole car modal with the standard A-chassis format with the driveseat, A-chassis tune, body, misc and wheels. The device/system is under the body section.

The second picture is the group model of the device/system. The script is using a localscript (Ignore the disabled localscript)

Screen Shot 2022-06-17 at 9.35.15 PM

I hope this is relevant

1 Like