Introduction and what I’m making
So I am making a street speed camera that displays your speed once you touch a part. The part is long enough to update the speed a few times.
Problem
So the problem I am having is that even though the part “Highway” (the ground/base of the road that can be seen in the photo above) is in my “Ignored” list, it still casts on it.
Here is a photo showing that the raycast is casting on the highway, not the “InitiateSpeedRadar” part:
Code
The code is a server script inside of the raycasting part (street camera):
local SpeedRadar = script.Parent
local InitiateSpeedRadar = workspace:FindFirstChild("InitiateSpeedRadar")
local db = false
InitiateSpeedRadar.Touched:Connect(function(otherPart)
local RayCastParams = RaycastParams.new()
RayCastParams.FilterType = Enum.RaycastFilterType.Blacklist
RayCastParams.FilterDescendantsInstances = {SpeedRadar, workspace.Highway}
local rayOrigin = SpeedRadar.Position
local rayDirection = Vector3.new(36.344, -3.486, -49.566)
local RaycastResult = workspace:Raycast(rayOrigin, rayDirection, RayCastParams)
if RaycastResult then
print("Raycasting!")
print(otherPart.Name)
if db == false then
db = true
print(otherPart.Name)
if otherPart:IsA("Part") then
if otherPart.Parent:IsA("Model") then
if not otherPart.Parent:FindFirstChild("DriveSeat") then
db = false
return print("No seat detected!")
else
print("Parent detected")
local driveSeat = otherPart.Parent.DriveSeat
local speed = driveSeat.Velocity.Magnitude
local formattedSpeed = math.floor(speed + 0.5)
if formattedSpeed >= 100 then
SpeedRadar.SurfaceGui.Speed.Text = "SLOW DOWN!"
print("FAST!")
else
SpeedRadar.SurfaceGui.Speed.Text = formattedSpeed
end
wait(0.5)
db = false
end
else
db = false
return print("Plain part detetced!")
end
else
db = false
return warn("Not a model")
end
end
end
end)
Once it tells me it raycasted on the highway, it breaks and it doesn’t work afterward.
Important Notes
- The script should be initiating only if another part is touching it…
- I tested the script earlier and it worked, but it wasn’t in the same game. The only thing I changed was the direction.