So I'm trying to make a "Speed detector" for cars that go over the speed limit, if they touch the part and are over the speed limit they get a fine for speeding (100 HRK). Everything works except when I want to check the speed, I'm not sure how to do it. I use the A-Chassis System for my cars. Also, I'm unsure if I can check the WalkSpeed if the player is sitting.
How can I fix this or how can I make the Speed detector, it's really important and it means a lot to me if you help me out. Thanks!
db = false
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if db == false then
db = true
script.Parent.BrickColor = BrickColor.new("Bright red")
player.leaderstats.HRK.Value = player.leaderstats.HRK.Value - 100
wait(3)
script.Parent.BrickColor = BrickColor.new("Bright green")
db = false
end
end
end)

11 comments
Hey, The script doesn't work for players that are inside the car and for players that are normally walking over 16.
It worked fine for me, and for the cars, I recommend instead of trying to get the player inside of the car, you can get the magnitude of the car or any part of the car.
How can i do that? Im new to scripting, so most of the times stuff makes almost no sense to me, haha ;')
You could do something similar to what I did. Use a Part Touched event and check if the part that touched it is a child of a car. This could be done through many ways like getting the name, having a indicator inside the car, etc. Once you've detected it is a car get the magnitude of any part or the vehicle seat by doing [part name].Velocity.Magnitude. If the magnitude is over a specific amount (1)
, they would get a speeding ticket. You could also learn about Region3s and set up specific regions in which a player could get a ticket for speeding in specific areas, but I'm getting side tracked.
I'll see if I can make a script for you to look at.
Hmm, im not really understanding most of this sadly.. Is there any way you could possibly create another script for me? I'm new to the scripting, and i can make more "advanced" scripts with the help of youtube tutorials. + There is almost 0 videos on how to do a speed detector for a car. It would really mean a lot to me if i got it working, since its the part of the game im working on.
Please see my updated post.
Hey, so the "local eligblenames = {"Chassis"} -- your table to store car names." Is the Chassis part a folder, since its not the same name for me?
No, its a table. You can put the name of the car in there, separated by a comma, for example, “local eligiblecars = {“Chassis”, “Ford F150”}”. I recommend learning about tables.
Works, ty :) <3