Is my function reliable?
Essentially, I'm making a datastore system for players to buy vehicles using DataStore2.This function that I made saves the aircraftName into a table once bought, so there is no need to save anything after the player leaves, and there's no need to load anything when the player joins.
function module:BuyAircraft(player ,aircraftName)
local airCraft = aircraftModule[aircraftName]
if not airCraft then return end
local aircraftStore = DataStore2("PlayerAircraft", player)
aircraftStore:Get({})
local currentAircrafts = table.clone(aircraftStore.value)
-- This returns if player cant buy the aircraft or already owns it.
if not currencyModule:ableToBuy(player, airCraft.Costs.CostType, airCraft.Costs.Cost) or module:ownsAircraft(player, aircraftName) then return end
-- essentially just subtracts the currency.
currencyModule:subtractCurrency(player, airCraft.Costs.CostType, airCraft.Costs.Cost)
-- adds the name of the aircraft to the duplicated aircraft table.
table.insert(currentAircrafts, aircraftName)
aircraftStore:Set(currentAircrafts)
end