Point subtraction system help

Hello!

I am trying to create a realistic driving game and I wanted to implement a driving challenge and if the player crashes or bumps into something it will take a certain amount of points away from them.

Currently, I have tried many methods and non of them seem to work so I’ve decided to post here.

Here is the script I’m using that detects if the vehicle hits something

script.Parent.Touched:Connect(function(hitturn)
	if hitturn.Name == "Object" then
		print("You crashed")
		wait(1)
		end
	end)

This code is just placed into the body mesh of the car so whenever the actual body touches something it’s detected.

If you need anymore info please let me know!

Thank you.

Feel free to download this test version:
Test2.rbxl (101.8 KB)

there are many times to detect if a player crashes, easier would be to compare speed.

for example.
If the player went from 100 MPH to 0 mph in 2 seconds, of course he crashed.

This will work.

Replace your leaderstats script with this:

--//Services
local Players = game:GetService("Players")

--//Functions
Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local score = Instance.new("NumberValue")
	score.Name = "Points"
	score.Value = 2
	score.Parent = leaderstats
end)

Replace your detect script with this:

--//Services
local Players = game:GetService("Players")

--//Variables
local Detect = script.Parent
local Vehicle = Detect.Parent.Parent
local Debounce = false

--//Functions
Detect.Touched:Connect(function(hitpart)
	if hitpart.Name == "Object" and not Debounce then
		Debounce = true
		
		local Player = Players:GetPlayerFromCharacter(Vehicle.DriveSeat.Occupant.Parent)
        if Player and Player.leaderstats.Points.Value > 0 then
           Player.leaderstats.Points.Value -= 1 -- amount of points taken away
        end
		
		task.wait(1)
		Debounce = false
	end
end)
score.Changed:Connect(function(newScore)
	if newScore <= 0 then
		score.Value = 2 --reset back to 2 to prevent negative stat value
	end
end)

This isn’t a critique of your code, more something the original poster can decide to add to the leaderstats script at his own discretion.