I’m trying to save datastore tables; which are important for my development project since I also need to save data of the player / edit it too.
The work I am trying to do is a Vehicle Ownership datastore.
Everything works fine no errors; it’s a problem with datastore and it just only saves one value when I buy a car; and it thinks that the other car is same as the value but instead the name of the car and the strings and information are different.
Server Script:
local remote = game.ReplicatedStorage.BuyCar
local remote2 = game.ReplicatedStorage.CheckIfOwned
local module = require(game.ServerScriptService.CarData)
local prompt = game.ReplicatedStorage.Prompt
local datastore = game:GetService("DataStoreService")
local data = datastore:GetDataStore("BoughtCars")
local data2 = nil
local data3 = nil
remote.OnServerInvoke = function(plr, stringcode)
local d,p = pcall(function()
data3 = data:GetAsync(plr.UserId)
end)
if data3 ~= nil then
if not table.find(data3.OwnedCars, stringcode) then
if stringcode and plr then
for i,v in module.Enums.Normal do
if v[tostring(stringcode)] then
if v[tostring(stringcode)].Price <= plr.leaderstats.Money.Value then
plr.leaderstats.Money.Value = plr.leaderstats.Money.Value - tonumber(v[tostring(stringcode)].Price)
local s,r = pcall(function()
data2 = data:SetAsync(plr.UserId, {OwnedCars = {stringcode}})
end)
end
end
end
else
assert(stringcode, stringcode .. "not found. (table identifier)")
end
elseif table.find(data3.OwnedCars, stringcode) then
print("Already bought.")
end
else
if stringcode and plr then
for i,v in module.Enums.Normal do
if v[tostring(stringcode)] then
if v[tostring(stringcode)].Price <= plr.leaderstats.Money.Value then
plr.leaderstats.Money.Value = plr.leaderstats.Money.Value - tonumber(v[tostring(stringcode)].Price)
local s,r = pcall(function()
data2 = data:SetAsync(plr.UserId, {OwnedCars = {stringcode}})
end)
else
game.ReplicatedStorage.R2:FireClient(plr)
end
end
end
end
end
return data2
end
remote2.OnServerInvoke = function(plr)
local d,p = pcall(function()
data3 = data:GetAsync(plr.UserId)
end)
if data3 ~= nil then
for i,v in data3.OwnedCars do
print(v)
end
end
return data3
end
ModuleScript Data:
local cardata = {}
cardata.Enums = {
Normal = {
Nissan = {
["Y60"] = {
Price = 27500;
EOName = "Y60"
};
["NissanPatrolSSWhiteOFFRoad"] = {
Price = 25000;
EOName = "NissanPatrolSSWhiteOFFRoad"
};
};
Lexus = {
};
Honda = {
};
BMW = {
};
Mitsubishi = {
};
Volvo = {
};
Motorbikes = {
};
Buggy = {
};
Toyota = {
["LandCruiser"] = {
Price = 30000;
EOName = "LandCruiser"
};
["LC100"] = {
Price = 28000;
EOName = "LC100"
};
["LCGXR"] = {
Price = 28000;
EOName = "LCGXR"
};
};
Suzuki = {
}
};
}
return cardata
local player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SpawnCarEvent = ReplicatedStorage:WaitForChild("SpawnCar")
local TS = game:GetService("TweenService")
local SVE = ReplicatedStorage.CheckIfOwned
local DeleteCarEvent = ReplicatedStorage:WaitForChild("DeleteCar")
local prompt = game.ReplicatedStorage.Prompt
local BuyCar = ReplicatedStorage.BuyCar
local carName = script.Parent.Parent.Name
local SpawnCarFrame = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent
local owned = SVE:InvokeServer("NissanPatrolSSWhiteOFFRoad")
script.Parent.MouseButton1Click:Connect(function()
if owned ~= nil then
if owned.OwnedCars then
SpawnCarFrame.Visible = false
task.wait()
SpawnCarEvent:FireServer("Admin Car Ace Country")
elseif tostring(owned.OwnedCars) ~= "NissanPatrolSSWhiteOFFRoad" then
local rep = BuyCar:InvokeServer("NissanPatrolSSWhiteOFFRoad")
if rep then
script.Parent.Text = "SPAWN"
SpawnCarEvent:FireServer("Admin Car Ace Country")
else
TS:Create(script.Parent, TweenInfo.new(0.8, Enum.EasingStyle.Quint, Enum.EasingDirection.Out), {TextColor3 = Color3.fromRGB(255,0,0)}):Play()
prompt:FireServer(script.Parent.Text)
task.wait(4)
TS:Create(script.Parent, TweenInfo.new(0.8, Enum.EasingStyle.Quint, Enum.EasingDirection.Out), {TextColor3 = Color3.fromRGB(15, 59, 0)}):Play()
end
else
local rep = BuyCar:InvokeServer("NissanPatrolSSWhiteOFFRoad")
if rep then
script.Parent.Text = "SPAWN"
SpawnCarEvent:FireServer("Admin Car Ace Country")
else
TS:Create(script.Parent, TweenInfo.new(0.8, Enum.EasingStyle.Quint, Enum.EasingDirection.Out), {TextColor3 = Color3.fromRGB(255,0,0)}):Play()
prompt:FireServer(script.Parent.Text)
task.wait(4)
TS:Create(script.Parent, TweenInfo.new(0.8, Enum.EasingStyle.Quint, Enum.EasingDirection.Out), {TextColor3 = Color3.fromRGB(15, 59, 0)}):Play()
end
end
else
local rep = BuyCar:InvokeServer("NissanPatrolSSWhiteOFFRoad")
if rep then
script.Parent.Text = "SPAWN"
SpawnCarEvent:FireServer("Admin Car Ace Country")
else
TS:Create(script.Parent, TweenInfo.new(0.8, Enum.EasingStyle.Quint, Enum.EasingDirection.Out), {TextColor3 = Color3.fromRGB(255,0,0)}):Play()
prompt:FireServer(script.Parent.Text)
task.wait(4)
TS:Create(script.Parent, TweenInfo.new(0.8, Enum.EasingStyle.Quint, Enum.EasingDirection.Out), {TextColor3 = Color3.fromRGB(15, 59, 0)}):Play()
end
end
end)
Output: 15:22:47.381 ▼ NissanPatrolSSWhiteOFFRoad (x5) - Server - BuyCar:68
15:22:47.381 NissanPatrolSSWhiteOFFRoad
15:22:47.381 NissanPatrolSSWhiteOFFRoad
15:22:47.415 NissanPatrolSSWhiteOFFRoad
15:22:47.551 NissanPatrolSSWhiteOFFRoad
Also; the Admin Ace Car County thing is a free model. It’s just for test purposes and I don’t use it in realtime development.
So if you are willing to help me, I’ll be glad!