local HTTPs = game:GetService('HttpService')
local T = tick()
local Radars = {}
Radars.AddRadar = function(Part)
Part.Transparency = 1
Part.CanCollide = false
Part.Touched:Connect(function(HitPart)
if (tick() - T) < 4 then
return
end
T = tick()
if HitPart:IsDescendantOf(workspace.Map) then
return
end
local Player = game.Players:GetPlayerFromCharacter(HitPart.Parent)
if (Player) then
if (Player.Team ~= game.Teams.Civilian) then
return
end
if (Player.Character) then
if (Player.Character:FindFirstChild('Humanoid') or false) then
if (Player.Character.Humanoid.Health > 0) then
local Velocity = Player.Character.HumanoidRootPart.Velocity.Magnitude/2
if (Velocity > tonumber(Part.Name) or 100) then
print(Player:GetFullName(),' speeding with a velocity of: '..Velocity)
end
end
end
end
end
end)
end
return Radars
That’s my code.
It’s a radar, that detects if player’s speeding.
Works amazing!
Just… one thing.
It lags a lot when going with vehicles.
How can I fix this?
Should I use Physics, and set collide groups?
Edit: tried that, still same results
This part might be pretty expensive and not completely necessary. Say there was hundreds of thousands of instances inside Workspace → Map than that function would need to check against several things.
if HitPart:IsDescendantOf(workspace.Map) then
return
end
.Touched will fire every time the part is touched, and with high detail items made of thousands of parts, this can fire 1000s of times in a second. You have a few choices:
• Reduce the size of the part that the touched event is connected to
• Reduce the amount of parts a vehicle has
• FindPartsInRegion3
• Changing to a distance based function
I would change the size of the part to make it only like a speed bump on the road that the wheels touch.
If it is the case of too many touch events fired because of several parts another good solution would be creating the collision groups. with like only the humanoid root part and the radars.
Could you name the car the player’s name or place the wheels in a consistent place (under a “wheel” model under the car model or something like that) that you can get the car’s seat and get the occupant of the seat and get the player that way?
Example:
Part.Touched:Connect(function(Hitpart)
if Hitpart.Parent.Name == "Wheels" and Hitpart.Parent.Parent.Seat.Occupant then
-- do the check for speeding, but get the Occupant of the seat, which is a humanoid.
end
end)