I am working on a plane crash game where players can fly around and collide with objects that will damage the plane. I want to know how I can make it so that if a player hits one wing and the wing falls off, the plane stops flying and simply falls to the ground.
Well do you have any code already?
i do but the code is so buggy sadly
Do you have a functional flying plane?
yes i do it can fly very good with some scripts
so i am working on a plane game with planes you can destroy by flying it into walls and i want to make the physics realistic like if one of my propeller breaks or one of my wings breaks the plane stops flying but ive tried much and i dont know what to do here is some of my script it also counts when the wing is detected to fall off
local Players = game:GetService("Players")
local function handleMissingWings()
for _, player in ipairs(Players:GetPlayers()) do
print("Checking wings for player:", player.Name)
local character = player.Character
if character then
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid and humanoid.SeatPart then
local planeModel = humanoid.SeatPart.Parent
if planeModel and planeModel:IsA("Model") then
local Wing1 = planeModel:FindFirstChild("Wing1")
local Wing2 = planeModel:FindFirstChild("Wing2")
if not (Wing1 and Wing2) then
print("Wings missing, initiating fall for player:", player.Name)
-- Wings are missing, forcefully stop the plane
local body = planeModel:FindFirstChild("Body")
if body and body:IsA("BodyVelocity") then
body:Destroy()
end
local bodyVelocity = Instance.new("BodyVelocity", body)
bodyVelocity.Velocity = Vector3.new(0, -30, 0) -- Set a downward velocity (adjust as needed)
end
end
end
end
end
end
while true do
handleMissingWings()
wait(1) -- Check every second (adjust as needed)
end
this script only works when you have your wing off and land the plane and jump out and jump in the plane again than it does work because it doesn’t let you go up
of my previous topic almost no one responded sadly
So you want the player to lose control of the plane and the plane to fall to the ground & no longer be able to be piloted?
yes thats the thing what i am trying to do
It sounds to me like you need a function which disables the driver’s seat essentially
it is a normal seat though you dont really need a drivers seat
Can you send me more screenies of the script/the plane? I’m afraid I don’t fully understand
what do you mean like what pictures do you need
If the wing falls off the plane, you can connect your function to stop the plane from flying to anything whose weld gets destroyed.
How I would do it is that I would create an attribute or a boolvalue under the plane’s group. When a part gets taken off the plane, make that value true. In the main script, I would connect the function which stope the plane from flying to whenever that boolvalue changes.
(P.S. that’s a really cool airplane)
ok ill try that be right back i will tell you if it works
Does your plane use in-game aerodynamics?
i dont think so i dont think i have ever added that
i think that this is the full script
– ServerScriptService.Script
local ServerStorage = game:GetService(“ServerStorage”)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local Players = game:GetService(“Players”)
local spawnPlaneEvent = ReplicatedStorage:WaitForChild(“SpawnPlaneEvent”)
local lastSpawnedPlanes = {}
local function cloneModel(original)
local clone = original:Clone()
-- Ensure all parts of the model are descendants
for _, part in pairs(clone:GetDescendants()) do
if part:IsA("BasePart") then
end
end
return clone
end
local function setModelCFrame(model, position)
local offset = Vector3.new(5, -5, 0) – You can adjust this offset as needed
local primaryPartName = "Seat" -- Replace with the actual name
local primaryPart = model:FindFirstChild(primaryPartName)
if primaryPart then
primaryPart.CFrame = CFrame.new(position + offset)
else
warn("PrimaryPart not found in the model.")
end
end
spawnPlaneEvent.OnServerEvent:Connect(function(player)
local character = player.Character
if character then
local lastSpawnedPlane = lastSpawnedPlanes[player]
if lastSpawnedPlane then
lastSpawnedPlane:Destroy() -- Remove the last spawned plane
end
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
local planeModel = cloneModel(ServerStorage:WaitForChild('Plane'))
planeModel.Name = "Plane"
planeModel.Parent = workspace
setModelCFrame(planeModel, humanoid.Parent.PrimaryPart.Position)
lastSpawnedPlanes[player] = planeModel -- Update the last spawned plane for the player
end
end
end)
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
spawnPlaneEvent:FireClient(player)
end)
end)
local Players = game:GetService(“Players”)
local function handleMissingWings()
for _, player in ipairs(Players:GetPlayers()) do
local character = player.Character
if character then
local humanoid = character:FindFirstChildOfClass(“Humanoid”)
if humanoid and humanoid.SeatPart then
local planeModel = humanoid.SeatPart.Parent
if planeModel and planeModel:IsA("Model") then
local Wing1 = planeModel:FindFirstChild("Wing1")
local Wing2 = planeModel:FindFirstChild("Wing2")
if not (Wing1 and Wing2) then
-- Wings are missing, initiate a fall
local body = planeModel:FindFirstChild("Body")
if body and body:IsA("BodyGyro") then
body:Destroy()
end
local bodyVelocity = Instance.new("BodyVelocity", body)
bodyVelocity.Velocity = Vector3.new(0, -30, 0) -- Set a downward velocity (adjust as needed)
end
end
end
end
end
end
while true do
handleMissingWings()
wait(1) – Check every second (adjust as needed)
end