You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I want to make a car buying system, so people could drive in an immersive world. -
What is the issue? Include screenshots / videos if possible!
The cars aren’t saving, and instead when rejoining I need to rebuy the car, unless I will buy the car which I can just peacefully spawn it, and then rejoin and it’ll break. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried to see if I didn’t write something, since each car has it’s own value and I have to copy them over and over. I tried to also look for YouTube videos related to buying systems, but they did little to no help at all.
Each car has it’s own value. Let’s say I have a value called FORD car, it’s named FORDown (pretty much any car value has lowercase “own” in the end), and then a data variable called dataFORD, and this applies for 14 cars. If you didn’t understand what I said, I think you should look into the script.
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetOrderedDataStore("myDataStore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local credits = Instance.new("IntValue")
credits.Name = "credits"
credits.Parent = leaderstats
local JZA80own = Instance.new("BoolValue")
JZA80own.Name = "JZA80own"
JZA80own.Parent = leaderstats
local F40own = Instance.new("BoolValue")
F40own.Name = "F40own"
F40own.Parent = leaderstats
local FD7own = Instance.new("BoolValue")
FD7own.Name = "FD7own"
FD7own.Parent = leaderstats
local GT3RS991own = Instance.new("BoolValue")
GT3RS991own.Name = "GT3RS991own"
GT3RS991own.Parent = leaderstats
local E30own = Instance.new("BoolValue")
E30own.Name = "E30own"
E30own.Parent = leaderstats
local RS3own = Instance.new("BoolValue")
RS3own.Name = "RS3own"
RS3own.Parent = leaderstats
local Z370own = Instance.new("BoolValue")
Z370own.Name = "Z370own"
Z370own.Parent = leaderstats
local PUNTOown = Instance.new("BoolValue")
PUNTOown.Name = "PUNTOown"
PUNTOown.Parent = leaderstats
local TTRSown = Instance.new("BoolValue")
TTRSown.Name = "TTRSown"
TTRSown.Parent = leaderstats
local POLOown = Instance.new("BoolValue")
POLOown.Name = "POLOown"
POLOown.Parent = leaderstats
local RC206own = Instance.new("BoolValue")
RC206own.Name = "RC206own"
RC206own.Parent = leaderstats
local RLY206own = Instance.new("BoolValue")
RLY206own.Name = "RLY206own"
RLY206own.Parent = leaderstats
local AUDIF1own = Instance.new("BoolValue")
AUDIF1own.Name = "AUDIF1own"
AUDIF1own.Parent = leaderstats
local dataJZA80
local dataF40
local dataFD7
local dataGT3991RS
local dataE30
local dataRS3
local dataZ370
local dataPUNTO
local dataTTRS
local dataPOLO
local dataRC206
local dataRLY206
local dataAUDIF1
local creditdata
local success, errormessage = pcall(function()
creditdata = myDataStore:GetAsync(player.UserId.."-credits")
dataJZA80 = myDataStore:GetAsync(player.UserId.."-JZA80own")
dataF40 = myDataStore:GetAsync(player.UserId.."-F40own")
dataFD7 = myDataStore:GetAsync(player.UserId.."-FD7own")
dataGT3991RS = myDataStore:GetAsync(player.UserId.."-GT3991RSown")
dataE30 = myDataStore:GetAsync(player.UserId.."-E30own")
dataRS3 = myDataStore:GetAsync(player.UserId.."-RS3own")
dataZ370 = myDataStore:GetAsync(player.UserId.."-Z370own")
dataPUNTO = myDataStore:GetAsync(player.UserId.."-PUNTOown")
dataTTRS = myDataStore:GetAsync(player.UserId.."-TTRSown")
dataPOLO = myDataStore:GetAsync(player.UserId.."-POLOown")
dataRC206 = myDataStore:GetAsync(player.UserId.."-RC206own")
dataRLY206 = myDataStore:GetAsync(player.UserId.."-RLY206own")
dataAUDIF1 = myDataStore:GetAsync(player.UserId.."-AUDIF1own")
end)
if success then
credits.Value = creditdata
JZA80own.Value = dataJZA80
F40own.Value = dataF40
FD7own.Value = dataFD7
GT3RS991own.Value = dataGT3991RS
E30own.Value = dataE30
RS3own.Value = dataRS3
Z370own.Value = dataZ370
PUNTOown.Value = dataPUNTO
TTRSown.Value = dataTTRS
POLOown.Value = dataPOLO
RC206own.Value = dataRC206
RLY206own.Value = dataRLY206
AUDIF1own.Value = dataAUDIF1
else
print("There was an error while getting your data")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId.."-credits",player.leaderstats.credits.Value)
myDataStore:SetAsync(player.UserId.."-JZA80own",player.leaderstats.JZA80own.Value)
myDataStore:SetAsync(player.UserId.."-F40own",player.leaderstats.F40own.Value)
myDataStore:SetAsync(player.UserId.."-FD7own",player.leaderstats.FD7own.Value)
myDataStore:SetAsync(player.UserId.."-GT3991RSown",player.leaderstats.GT3991RSown.Value)
myDataStore:SetAsync(player.UserId.."-E30own",player.leaderstats.E30own.Value)
myDataStore:SetAsync(player.UserId.."-RS3own",player.leaderstats.RS3own.Value)
myDataStore:SetAsync(player.UserId.."-Z370own",player.leaderstats.Z370own.Value)
myDataStore:SetAsync(player.UserId.."-PUNTOown",player.leaderstats.PUNTOown.Value)
myDataStore:SetAsync(player.UserId.."-TTRSown",player.leaderstats.TTRSown.Value)
myDataStore:SetAsync(player.UserId.."-POLOown",player.leaderstats.POLOown.Value)
myDataStore:SetAsync(player.UserId.."-RC206own",player.leaderstats.RC206own.Value)
myDataStore:SetAsync(player.UserId.."-RLY206own",player.leaderstats.RLY206own.Value)
myDataStore:SetAsync(player.UserId.."-AudiF1own",player.leaderstats.AudiF1own.Value)
-- myDataStore:SetAsync(player.UserId.."-credits",player.leaderstats.JZA80own.Value)
end)
if success then
print(player.."'s Data Successfully Saved!")
else
print(player.."s Datas was an error when saving data")
warn(errormessage)
end
end)
The code is pretty immense, but I tried my best to explain this.
Thanks, vxcaie