Hello! I have a Plane and this script on the platform it appears.
Basically it makes a clone of the plane if someone takes it a bit far away. I want it so the Cloned Planes also get deleted if the Seat is empty for a while (that way i know nobody is using the cloned plane anymore)
here is the script:
local current = script.Parent.Parent.Parent.Parent:FindFirstChild("PlaneFlying")
local copy = current:Clone()
function add()
if current.Parent then
current.Parent = game.Workspace
end
local c = copy:Clone()
c.Parent = script.Parent.Parent
c:makeJoints()
current = c
end
while true do
wait(5)
if (script.Parent.Position - current.VehicleSeat.Position).magnitude > 20 then
add()
end
end
How could i change this so the cloned planes despawn after no longer being used
i would try using the plane’s seat as a way to destory the plane’s Captain if not seated
--try something like this
while wait(5) do
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local plane = script.Parent.Parent.Model
local function onSeated(isSeated, seat)
if isSeated then
print("Everything is good")
else
plane:Destory() --add you're own model here
end
end
humanoid.Seated:Connect(onSeated)
end
This will create a new function every 5 seconds that will fire when a player sits, then if a player does sit, it’s going to only delete the plane if a player isn’t sitting after a player sits.
Instead, have one main script that will start a timer for each plane when a player gets up, then delete the plane after the timer is up.