any one can help me how i cant saver player car
the car is model
any one can help me how i cant saver player car
the car is model
Tell in more detail:
1. Is the car an object (model) or some kind of meaning?
2. Do you have at least a DataStore?
yes Model
2. What do you mean have datastore You ask, I can program data??
What exactly do you mean with this? Do you want to save only a single car or an entire table of them?
I need to learn how to save one model in the beginning
Read this article first, then look at this storage example without your model.
Let’s get to know DataStore! This is a service that allows you to save data (as you could read from the article)
--ServerScript
local DataStoreService = game:GetService("DataStoreService") --Get Service
local DataStore = DataStoreService:GetDataStore("SaveData") --Your Name DataStore
game.Players.PlayerAdded:Connect(function(player) --When Player Added function start
--for ex.:
--Instance Folders
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
--Instance orderinary Int/Number/String Values
--Money
local Money = Instance.new("StringValue")
Money.Name = "Money"
Money.Value = tostring(0)
Money.Parent = leaderstats
--Load From Tabel
local tableOfData --Name table with data
local success, errormessage = pcall(function()
tableOfData = DataStore:GetAsync(player.UserId) -- Key to player
end)
if success and tableOfData then
for key, value in pairs(tableOfData) do --process loading data
Money.Value = tableOfData["Money"]
end
else --If this New Player
Money.Value = tostring(0)
end
end)
game.Players.PlayerRemoving:Connect(function(player) --When Player Removing
--Here we adding values for data
local tableOfData = {
["Money"] = player.leaderstats.Money.Value,
}
local success, errormessage = pcall(function()
print(tableOfData) -- Test Data Store
DataStore:SetAsync(player.UserId, tableOfData) --Saving to Server Process
end)
end)
In order to save the purchase, we need something to be saved! Let the player store a StringValue from the value of the machine and this StringValue must be stored in a certain folder
--ServerScript
local DataStoreService = game:GetService("DataStoreService") --Get Service
local DataStore = DataStoreService:GetDataStore("SaveData") --Your Name DataStore
local ReplicatedStorage = game:GetService("ReplicatedStorage")
game.Players.PlayerAdded:Connect(function(player) --When Player Added function start
--for ex.:
--Instance Folders
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local PurchaseCars = Instance.new("Folder") -- Folder For Purchase
PurchaseCars.Name = "PurchaseCars"
PurchaseCars.Parent = player
--Instance orderinary Int/Number/String Values
--Money
local Money = Instance.new("StringValue")
Money.Name = "Money"
Money.Value = tostring(0)
Money.Parent = leaderstats
--Load From Tabel
local tableOfPurchaseCars = {} --Table for cars
local tableOfData --Name table with data
local success, errormessage = pcall(function()
tableOfData = DataStore:GetAsync(player.UserId) -- Key to player
end)
if success and tableOfData then
for key, value in pairs(tableOfData) do --process loading data
Money.Value = tableOfData["Money"]
tableOfPurchaseCars = tableOfData["tableOfPurchaseCars"]
end
else --If this New Player
Money.Value = tostring(0)
end
if tableOfPurchaseCars ~= nil then
for _, value in pairs(tableOfPurchaseCars) do
local New = Instance.new("StringValue")
New.Parent = PurchaseCars
New.Value = value.ValueForValue
New.Name = value.ValueName
local Cars = ReplicatedStorage.Cars:FindFirstChild(value.ValueForValue):Clone()
Cars.Parent = workspace --here put where you need
end
end
end)
game.Players.PlayerRemoving:Connect(function(player) --When Player Removing
--Here we adding values for data
local tableOfPurchaseCars = {}
for i,v in ipairs(player.PurchaseCars:GetChildren()) do
table.insert(tableOfPurchaseCars, {ValueName = v.Name, ValueForValue = v.Value})
end
local tableOfData = {
["Money"] = player.leaderstats.Money.Value,
["tableOfPurchaseCars"] = tableOfPurchaseCars,
}
local success, errormessage = pcall(function()
print(tableOfData) -- Test Data Store
DataStore:SetAsync(player.UserId, tableOfData) --Saving to Server Process
end)
end)
ReplicatedStorage ex:
![]()
PurchaseCars - the place where your script should create a StringValue with the value of the name car