Trying to calculate the players speed

Hello There,

In the script I have in this post what I’m trying to do is when the player hit the part the script calculates the players speed to KM/H but I tried some many times and I can’t get it to calculate the players speed.

Script

local Players = game:GetService("Players")
local speedLimit = script.Parent.Parent.Parent:WaitForChild("SpeedLimit")
local Gui = script:WaitForChild("Ticket")
debounce = false
print(speedLimit.Value.."kph | Has Been Set for Andover Speed Camera")

script.Parent.Touched:Connect(function(hit)
	if debounce == false then
		debounce = true
		local player = hit.AssemblyLinearVelocity.Magnitude
		if hit.Parent:FindFirstChild("Humanoid") then 
			if (math.floor(hit.AssemblyLinearVelocity.Magnitude)) >= speedLimit.Value then
				local player = Players:FindFirstChild(hit.Parent.Name)
				print("Players Speed before they get a ticket "..math.floor(hit.AssemblyLinearVelocity.Magnitude))
				if hit.AssemblyLinearVelocity.Magnitude >= speedLimit.Value then
					local clone = Gui:Clone()
					clone.Parent = player.PlayerGui
					player.leaderstats.Pounds.Value = player.leaderstats.Pounds.Value - 100
					player.leaderstats.Bounty.Value = player.leaderstats.Bounty.Value + 15
					wait(2)
					clone:Destroy()
				else

				end
			end
		end
		debounce = false
	end
end)

If someone can help me calculate the players speed that would be great.

2 Likes

Hi,is the Player’ Speed AssemblyLinearVelocity.Magnitude?

1 Like

Well that’s what it is in the script. I did just Thought of changing it to Velocity instead.

Kmh = math.floor(hit.AssemblyLinearVelocity.Magnitude*(20000/3600))

Try this

1 Like

It said my speed was 1174 KM/H

I did do it again but I changed it to Velocity

use velocity and devide by 3.571429 (use math.floor)

this should work

I believe this may be the calculation you are looking for. I am unsure whether it is the Magnitude or AssemblyLinearVelocity that you need so perhaps try both.

local mps = BasePart.AssemblyLinearVelocity.Magnitude / 3.571429 -- m/s
local kmph = mps * 3.6 -- km/h
2 Likes

image

Was that the expected speed or not?

Kinda But That Was not the speed I was doing. I was doing 113

1 Like

Never mind it worked I just Had to change the Units in the car

1 Like

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