-
What are you attempting to achieve? (Keep it simple and clear)
I’m trying to check if the car is owned by the Player(If it’s in the owned table in the DataStore)
-
What is the issue? (Keep it simple and clear - Include screenshots/videos/GIFs if possible)
If i try to get the table after setting it then it returns nil. I set it on line 21 in ‘OnCarPurchase’
Video -
What solutions have you tried so far? (Have you searched for solutions through the Roblox Wiki yet?)
I don’t remember
v–DataStore2Script–v
local DataStore2 = require(1936396537)
local defaultvalue = {}
local OwnedCars
game.Players.PlayerAdded:Connect(function(plr)
local carDataStore = DataStore2("OwnedCars", plr)
local function carsUpdate(updatedValue) -- updatedValue = default value OR passed in by OnUpdate
OwnedCars = carDataStore:Get(updatedValue)
end
carsUpdate(defaultvalue)
carDataStore:OnUpdate(carsUpdate)
end)
v–OnCarPurchase–v
game.ReplicatedStorage.PurchaseCar.OnServerEvent:Connect(function(Player, CarModelName)
local carDataStore = DataStore2("OwnedCars", Player)
if CarsAPI.Cars[CarModelName] then
print(carDataStore:Get())
if typeof(carDataStore:Get()) == "table" then
local OwnedCars = carDataStore:Get()
if OwnedCars[CarModelName] then
warn("Player has car")
elseif not OwnedCars[CarModelName] then
if Money > CarsAPI.Cars[CarModelName].Price then
print("Has enough money to buy")
local TableWithAddedCar = table.insert(OwnedCars, #OwnedCars + 1, CarModelName)
carDataStore:Set(TableWithAddedCar)
print(Player.Name.." Purchased "..CarModelName)
else
warn(Player.Name.." Doesn't have enough money to buy "..CarModelName)
end
end
end
end
end)