hi guys so i have a plane that you can destroy and the plane counts until a wing has broke or fallen off at the end of the script i use body:destroy and for some reason it stops counting and if i remove that it does keep counting when i spawn a new plane and i need the destroy body function to take the plane down can anyone help me fix this
-- 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
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")
body:destroy()
end
end
end
end
end
end
while true do
handleMissingWings()
wait(1) -- Check every second (adjust as needed)
end
return