I had a friend help me create a script for a flying thing, however, we can't seem to get the health to work, and the thing keeps changing locations of stuff on the plane, We have adjusted the values of our scripts and tried several different methods, studio doesn't really show any errors. I also wanted to get feedback as to how well we did on this script, it took a while to make and I wanted to see if there was anything I should do differently.\
wait(1) local v = script.Parent local seat = v.DriverSeat local engine = v.Engine local pos = engine.Pos local rot = engine.Rot local Parts = 0 local start = 0 local destroyed = false local max_health = 5000 local armor = v.Armor armor.Value = max_health local bar = script.Parent.ArmorBar local fires = 0 function Weld() local rep = game.Lighting:findFirstChild(script.Parent.Name) local e = engine:GetChildren() for i=1,#e do if e[i].className == "Weld" then e[i]:destroy() end end e = v:GetChildren() for i=1,#e do if e[i]:IsA("BasePart") and e[i]~=engine then local w = Instance.new("Weld",engine) w.Name = "Weld"..e[i].Name w.Part0 = engine w.Part1 = e[i] w.C0 = rep:findFirstChild("Engine").CFrame:inverse() w.C1 = rep:findFirstChild(e[i].Name).CFrame:inverse() end end engine.Anchored = false engine.CFrame = engine.CFrame + Vector3.new(0,0.1,0) engine.Anchored = true engine.CFrame = engine.CFrame - Vector3.new(0,0.1,0) for i=1,#e do if e[i]:IsA("BasePart") then e[i].Anchored = false end end end seat.ChildAdded:connect(function(w) if w.className == "Weld" and w.Name == "SeatWeld" then wait() local t = w.Part1 if t~=nil and t.Parent~=nil then local char = t.Parent local pilot = game.Players:GetPlayerFromCharacter(char) if pilot ~= nil then local ctrl = script.Control:clone() ctrl.Vehicle.Value = v ctrl.Disabled = false ctrl.Parent = pilot.PlayerGui end end end end) Weld() function Explode() pcall(function() local e = v.Engine:GetChildren() for i=1,#e do e[i]:destroy() end local e = v:GetChildren() local center = v.Part10.CFrame.p for i=1,#e do if e[i]:IsA("BasePart") then e[i].Velocity = e[i].Velocity + (e[i].CFrame.p-center).unit * math.random(30,80) end end local boom = Instance.new("Explosion",workspace) boom.Position = center boom.BlastPressure = 10 boom.BlastRadius=20 end) delay(7.5,function() local e=v:GetChildren() for i=1,#e do if e[i]:IsA("BasePart") then e[i]:destroy() wait() end end v:destroy() end) end function ImpactDamage(hit, self) if hit ~=nil then if hit.Parent~=nil and hit.Parent:findFirstChild("Humanoid") ~=nil and destroyed then hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - ((self.Velocity.magnitude)*10*(100+self:GetMass()/100))/1000 elseif hit.Parent ~= v and hit.CanCollide and not destroyed and hit.Parent:findFirstChild("Humanoid")==nil then --print(self.Velocity.magnitude,(self:GetMass()+20)) armor.Value = armor.Value - ((self.Velocity.magnitude)*10*(100+self:GetMass()/100))/500 end end end e = v:GetChildren() for i=1,#e do if e[i]:IsA("BasePart") then e[i].Touched:connect(function(hit) ImpactDamage(hit,e[i]) end) end end function UpdateBar() if armor.Value < 0 then if not destroyed then destroyed = true Explode() end armor.Value = 0 end if armor.Value < max_health /2 and fires < math.floor(15*(.5-armor.Value/max_health)) then local a = math.random(1,12) if a < math.random(2,4) then local f = Instance.new("Fire",v:GetChildren()[math.random(1,#v:GetChildren())]) f.Heat = 40*(.5-armor.Value/max_health) f.Size = f.Heat fires = fires + 1 end end bar.Mesh.Scale = Vector3.new(armor.Value/max_health,1,1) bar.Mesh.Offset = Vector3.new((1-armor.Value/max_health)*bar.Size.X/2,0,0) end
Many have been asking where and what the exact issue is, I don't really know where it is except that the first issue is with the health bar at the top, the health bar is actually not a humanoid, it is a brick that shrinks when the plane gets hit and when the bar hits a certain level the plain sets on fire, and when the health bar is gone the plane explodes, the other issue is with the wielding, somehow it keeps wielding random plane parts to the health bar.