Hi, i'm trying to add to the code below that if Hit has can collide set as false it doesn't change the value like "not game.Players:GetPlayerFromCharacter(Hit.Parent)" already achieves. But i believe im going about it the wrong way and would appreciate if someone could lead me the correct way!
This is the line i'm trying to add it to, so basically if the script.Parent is hit, i want it so if the part hit has can collide turned off it doesn't change the Health value.
if Speed > 30 and not game.Players:GetPlayerFromCharacter(Hit.Parent) and Hit.CanCollide == false then
The full code is below.
script.Parent.Touched:Connect(function(Hit)
local Speed = math.floor((script.Parent.Velocity - Hit.Velocity).magnitude)
if Speed > 30 and not game.Players:GetPlayerFromCharacter(Hit.Parent) and Hit.CanCollide == false then
script.Parent.Health.Value = script.Parent.Health.Value - script.Parent.Velocity.Magnitude / 1.06
print("You screwed your car up m8. Speed: "..Speed)
local RandomNumber = math.random(1, 2)
if RandomNumber == 1 then
local CollideSound1 = Instance.new("Sound", script.Parent)
CollideSound1.SoundId = "rbxassetid://490314550"
CollideSound1:Play()
else
local CollideSound2 = Instance.new("Sound", script.Parent)
CollideSound2.SoundId = "rbxassetid://215550851"
CollideSound2:Play()
end
if script.Parent.Health.Value <= 0 then
script.Parent.Smoke.Enabled = true
end
if script.Parent.Health.Value <= 0 then
script.Parent.Parent.Parent.Parent.Parent.DriveSeat.Disabled = true
script.Parent.Parent.Repair.BillboardGui.Enabled = true
end
elseif Speed < 30 and not game.Players:GetPlayerFromCharacter(Hit.Parent) then
print("Keep tryin. Speed: "..Speed)
end
end)
