So I’m trying to make an auto-driving car, and when you touch it you get damaged and flung backward
How can I make it do damage without it insta killing me?
Everything I’ve tried so far didn’t work
script.Parent.Car.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local char = hit.Parent
local fling = Instance.new("BodyVelocity")
fling.MaxForce = Vector3.new(1,0,1) * 100000
fling.Velocity = char.HumanoidRootPart.CFrame.lookVector * -100
fling.Parent = char.HumanoidRootPart
for count = 1, 10 do
wait(0.1)
fling.Velocity*= 0.7
fling:Destroy()
end
end
end)
local players = game:GetService("Players")
local parent = script.Parent
local car = parent.Car
local debounce = false
car.Touched:Connect(function(hit)
if debounce then
return
end
local hitModel = hit:FindFirstAncestorOfClass("Model")
if hitModel then
local hitPlayer = players:GetPlayerFromCharacter(hitModel)
if hitPlayer then
local hitHuman = hitModel:FindFirstAncestorOfClass("Humanoid")
local hitHrp = hitModel:FindFirstChild("HumanoidRootPart")
if hitHuman and hitHrp then
debounce = true
local BV = Instance.new("BodyVelocity")
BV.MaxForce = Vector3.new(100000, 0, 100000)
BV.Velocity = hitHrp.CFrame.LookVector *- 100
BV.Parent = hitHrp
for count = 1, 10 do
task.wait(0.1)
BV.Velocity *= 0.7
end
BV:Destroy()
debounce = false
end
end
end
end)
Shouldn’t the “BodyVelocity” instance be destroyed outside of the loop? Otherwise what would be the point of the increasing the body velocity’s “Velocity” property? I’ve also made some other minor optimisations/fixes, if you need any explained let me know.