Hi.
I'm currently making a script which makes cars slower by 30% when they drive on dirt, snow etc. The script I wrote works fine, the problem is that it activates when only 1 wheel is touching, and I'd like the script to work only when all 4 are touching the off-road surface. Despite my attempts at solving the problem, I end up with similar results. Any help would be appreciated.
local Wheels = script.Parent.Parent.Wheels:GetChildren()
function Slowing(RoadType)
if RoadType.Material ~= Enum.Material.Concrete then
local NormalCarSpeed = script.Parent.Parent:FindFirstChild("NormalCarSpeed")
NormalCarSpeed = NormalCarSpeed.Value / 100 * 70
script.Parent.MaxSpeed = NormalCarSpeed
else
script.Parent.MaxSpeed = script.Parent.Parent.NormalCarSpeed.Value
end
end
for i,v in pairs(Wheels) do
Wheels[i].Touched:Connect(function(TouchPart)
local RoadTouch = v:GetTouchingParts()
for i,v in pairs(RoadTouch) do
if v.Material ~= Enum.Material.Concrete then
Slowing(TouchPart)
end
end
end)
end
