Hey there! I’m Keanny, an upcoming developer currently developing on a game called “Globetrotter”. This question is reated to the game itself.
-
What do you want to achieve?
Saving item purchases. In this case, the items are cars. I want to be able to save car purchases into a table in the player, which is then saved into a datastore. Every time the player rejoins the game, the table will be loaded from the datastore. Then, the table is accessible to every part of the code using a BindableFunction.
For your information, there are 2 datastores in the game. One is the money datastore and the other is this. The money datastore works just fine.
Server Script Code:
local dataStoreService = game:GetService("DataStoreService")
local garageDataStore = dataStoreService:GetDataStore("moneyDataStore")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local garage = {}
garage.Parent = plr
local garageData
local success, failMessage = pcall(function()
garageData = garageDataStore:GetAsync(game.Players.LocalPlayer.UserId.."-garage")
end)
if success then
garage = garageData
else
print("whoops, failed to retrieve data.")
warn(failMessage)
end
end)
game.ReplicatedStorage:WaitForChild("CheckGarage").OnServerInvoke = function(player)
return player.garage
end
-
What is the issue?
When I ran the code above, there was an error saying that “garage” is not a valid member of Player. -
What solutions have you tried so far?
I searched up a lot of topics on tables and datastores (since I’ve never used them before) and I still don’t find any answers. I’ve checked the other datastore I have (which is the money datastore) and it works fine. (I did that just to confirm that I’ve implemented the datastore function correctly.
Any help would be much appreciated as this is my first post in the forums and this is the only thing left to finish the saving system. Thank you.
-Keanny