So I have a game with planes but there's a problem with them. Sometimes if I crash with them the camera breaks and stays where my character died even tho my character has already respawned. It says that Head is not a valid member of Model. I have no idea what to do so I'm hoping that someone here could help me with this problem.
repeat wait() until script.Parent.Welded.Value --This line makes the plane invulnerable to weapons when it is still welding
wait(0.1)
local Plane = script.Parent --Lines 3 - 10 set variables
local AutoCrash = Plane.AutoCrash
local Ejected = Plane.Ejected
local Engine = Plane.MainParts.Engine
local CanCrash = Plane.Customize.CanCrash
local Force = CanCrash.Force
local Crashed = Plane.Crashed
local Parts = {}
--------------------------------------------------------------------------
function Explode() --This function makes the plane explode
if (not Crashed.Value) then
Crashed.Value = true
Plane:BreakJoints()
local Explosion = Instance.new("Explosion")
Explosion.Parent = game.Workspace
Explosion.Position = Engine.Position
Explosion.BlastRadius = Plane:GetModelSize().magnitude / 1 --This makes the BlastRadius the size of the plane
Explosion.BlastPressure = 1e1
if Engine:findFirstChild("Thrust") then Engine.Thrust:Destroy() end
if Engine:findFirstChild("Direction") then Engine.Direction:Destroy() end
delay(5,function() Plane:Destroy() end) --This removes the plane after 5 seconds
end
end
function GetPlaneParts(Model) --This function gets all the parts on the plane
for _,v in pairs(Model:GetChildren()) do
if (v:IsA("BasePart")) then
table.insert(Parts,v) --This inserts all the parts into the "Parts" table
end
GetPlaneParts(v)
end
end
function onAutoCrash() --This function is activated when the AutoCrash value becomes true
if AutoCrash.Value then
Explode()
end
end
function DetectExplosions(Object) --This is a function that I created which detects explosions in the workspace
if Object.ClassName == "Explosion" then --If the object detected was an explosion...
if Object.BlastPressure > 0 then
local Dist = (Object.Position - Engine.Position).magnitude
if Dist <= (Object.BlastRadius + 1) then
if (not Crashed.Value) then
Explode()
end
end
end
end
end
function IsObstacle(Obj) --This function determines whether Obj is an obstacle that can be used to destroy the plane
if (not Obj:IsDescendantOf(Plane)) and Obj.CanCollide then
local PlaneTag = Obj:FindFirstChild("PlaneTag")
if (PlaneTag and PlaneTag.Value ~= Plane) or (not PlaneTag) then
return true
end
end
return false
end
function IsDescendantOfPlayer(Obj)
for _,v in pairs(game.Players:GetPlayers()) do
if v and v.Character then
if Obj:IsDescendantOf(v.Character) then
return v
end
end
end
return nil
end
GetPlaneParts(Plane) --This activates the "GetPlaneParts" function
for _,v in pairs(Parts) do --This gets all the parts in the "Parts" table
v.Touched:connect(function(Object) --This is activated if any of the bricks are touched
if (not Ejected.Value) then
if CanCrash.Value and (not Crashed.Value) then
if IsObstacle(Object) then
local Player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
if Player then
local HitPlayer = IsDescendantOfPlayer(Object)
if HitPlayer == Player then return end
end
if (v.Velocity.magnitude >= Force.Value) then
Explode()
end
end
end
elseif Ejected.Value then
if (not Crashed.Value) then
if IsObstacle(Object) then
if Object.Parent.Name ~= "EjectorSeat" then
if (not IsDescendantOfPlayer(Object)) then
Explode()
end
end
end
end
end
end)
end
game.Workspace.DescendantAdded:connect(DetectExplosions) --The detect explosions is a DescendantAdded function
AutoCrash.Changed:connect(onAutoCrash) --Pretty self explanatory. When the AutoCrash value is changed, the "onAutoCrash" function is activated

3 comments
Can you post your script so we can see why it says "Head is not a valid member of Model" ?
And just to check, do you have any LocalScripts running that alter the camera?
Yea there is 1 running. I found out why it breaks the camera. The plane has a script inside of it that makes it crash when it touches the ground on a certain speed. Now the bugs happens when I fly below the map and the map limit breaks the plane. The script won't work then and the camera doesn't reset. But I have no idea how to fix this.