Hey y’all.
Currently using a f1 car model (https://create.roblox.com/marketplace/asset/8462249673/Mercedes-Petronas-F1-Car) and I’ve made a track. I’d love to punish the player for cutting into track limits, ideally by making the car much slower when touching grass.
The car already has a way of detecting which surface it is on, via this dust effect script:
WheelModel = script.Parent:WaitForChild("Wheels")
dustEffect = script:WaitForChild("DustEffect")
wheels = {}
touchingparts = {}
for i, v in pairs(WheelModel:GetChildren()) do
if v:IsA("BasePart") then
table.insert(wheels, v)
dustEffect:Clone().Parent = v
table.insert(touchingparts, nil)
end
end
for i, v in pairs(wheels) do
v.Touched:connect(function(part)
touchingparts[i] = part
end)
end
RunService = game:GetService("RunService")
RunService.Heartbeat:connect(function()
for i, v in pairs(wheels) do
local speed = v.Velocity.magnitude
if speed > 20 then
if touchingparts[i].Material == Enum.Material.Grass or touchingparts[i].Material == Enum.Material.Pebble or touchingparts[i].Material == Enum.Material.Sand or touchingparts[i].Material == Enum.Material.Slate or touchingparts[i].Material == Enum.Material.Ground or touchingparts[i].Material == Enum.Material.Mud or touchingparts[i].Material == Enum.Material.LeafyGrass or touchingparts[i].Material == Enum.Material.Basalt or touchingparts[i].Material == Enum.Material.Rock or touchingparts[i].Material == Enum.Material.CrackedLava then
v.DustEffect.Rate = 5/100 * speed * 30
else
v.DustEffect.Rate = 0
end
else
v.DustEffect.Rate = 0
end
end
end)
Issue is, this script does not change anything about the physics and is merely cosmetic. How could I modify, use or repurpose this script to slow the car when off track? What values would I need to change to slow the car, and how I change them, given that they are stored in seperate scripts?
I strongly advise you check out the model yourself, because I can’t really describe the inner structure of the car. Thanks for the help in advance.