Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Making a car damaging system with FE Gun Kit But i have trouble damaging the car???

Asked by 1 year ago
Edited 1 year ago

So I'm making a car damaging system. I have the function for turning the car into a pile of scrap once it reaches 0 health, but I have trouble for making the car take damage once a player shoots at it with a gun from FE Gun Kit. Here is my code so far:

while true do
    wait(0.1)
    for i, v in pairs(Car:GetDescendants()) do
        if v:FindFirstChild("Attachment") then
            Health -= 50
        end
    end
end

The bullet part that the gun shoots is actually an Attachment that sticks to where you shot. So I tried making it so when it detects an attachment it lowers the health. However, that does not work. I dont get any errors but it does not lower the health! Please help

(If you want, here is the full code):

local Car = script.Parent.Parent["Humvee (blue)"]
local Health = script.Health
local Script1 = script.Parent["A-Chassis Tune"]
local Script2 = script.Parent.Body.Motors
local Seat = script.Parent.DriveSeat


while true do
    wait(0.5)
    for i, v in pairs(Car:GetDescendants()) do
        if v:FindFirstDescendant("Attachment") then
            Health -= 50
        end
    end
end

while true do
    wait(0.5)
    if Health.Value == 0 then
        for i, v in pairs(Car:GetDescendants()) do
            if v:IsA("Part") or v:IsA("MeshPart") then
                v.Material = Enum.Material.CorrodedMetal
                Script1:Destroy()
                Script2:Destroy()
                if Seat.Occupant then
                    Seat.Occupant.Parent.Humanoid.Health = 0
                end
            end
        end
    end
end

-KoalaKo_XD

Answer this question