I’m trying to familiarise myself more with coding, hence this question.
I have a Spaceship flight system where upon entering the Pilot Seat, the Ships Ownership is set to the Pilot and a Gui is inserted into the Player - allowing the Ship to be piloted via client.
This uses RunServices to change the Camera focus to the Starship, although upon exiting the seat - This GUI is destroyed.
General query, but is the Function destroyed when the GUI is as at that times its not in use?
No it is not destroyed, you have to Disconnect it as it says @MrNicNac
Only I’m not a fan of its code, even if it works fine so this is a another exemple
local RunService = game:GetService("RunService")
function onStep()
print("New step !")
end
local idkForName = RunService.Stepped:Connect(onStep) -- Connect the service to the function onStep
wait(5)
idkForName:Disconnect() -- Disconnect the service
Well, it depends on what’s going on in the code. You can detect if the player have leaving the seat with VehicleSeat/Occupant