local DataStoreService = game:GetService("DataStoreService")
local PlayerData = DataStoreService:GetDataStore("Player")
game.Players.PlayerAdded:Connect(function(plr)
local CarFolder = Instance.new("Folder",plr)
CarFolder.Name = "PlayerCarLimted"
------------------------------------------------------------------
local BatManCat = Instance.new("StringValue",CarFolder)
local GMCs = Instance.new("StringValue",CarFolder)
local ToytaSupra = Instance.new("StringValue",CarFolder)
----------------------------------------------------------------- NAMES
BatManCat.Name = "BatManCat"
GMCs.Name = "GMCs"
ToytaSupra.Name = "ToytaSupra"
---------------------------------------------------------------- Tabels
local CarLimtedTabels = {
BatManCat. Value,
GMCs.Value,
ToytaSupra.Value,
}
---------------------------------------------------------------- Data
local Data
local S , F = pcall(function()
Data = PlayerData:SetAsync(plr.UserId)
end)
if S then
CarLimtedTabels = Data
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
---------------------------------------------------------------- Tabels
local CarPlayer = {}
table.insert(CarPlayer, plr.PlayerCarLimted.BatManCat.Value)
table.insert(CarPlayer, plr.PlayerCarLimted.GMCs.Value)
table.insert(CarPlayer, plr.PlayerCarLimted.ToytaSupra.Value)
---------------------------------------------------------------- Data
local S , F = pcall(function()
PlayerData:SetAsync(plr.UserId, CarPlayer)
end)
if S then
print(S)
else
print(F)
end
end)```
2 Likes
It looks like the issue is in the line where you’re calling PlayerData:SetAsync(plr.UserId) to save the player’s car data to the data store. You need to pass the actual data you want to save as the second argument to the SetAsync method, but in your code you’re passing the CarPlayer table as a parameter to the pcall function instead of to SetAsync.
do this…
local DataStoreService = game:GetService("DataStoreService")
local PlayerData = DataStoreService:GetDataStore("Player")
game.Players.PlayerAdded:Connect(function(plr)
local CarFolder = Instance.new("Folder", plr)
CarFolder.Name = "PlayerCarLimted"
local BatManCat = Instance.new("StringValue", CarFolder)
local GMCs = Instance.new("StringValue", CarFolder)
local ToytaSupra = Instance.new("StringValue", CarFolder)
BatManCat.Name = "BatManCat"
GMCs.Name = "GMCs"
ToytaSupra.Name = "ToytaSupra"
local CarLimtedTabels = {
BatManCat.Value,
GMCs.Value,
ToytaSupra.Value,
}
local Data
local S, F = pcall(function()
Data = PlayerData:GetAsync(plr.UserId)
end)
if S and Data then
for i = 1, #Data do
CarLimtedTabels[i] = Data[i]
end
end
BatManCat.Value = CarLimtedTabels[1]
GMCs.Value = CarLimtedTabels[2]
ToytaSupra.Value = CarLimtedTabels[3]
end)
game.Players.PlayerRemoving:Connect(function(plr)
local CarPlayer = {
plr.PlayerCarLimted.BatManCat.Value,
plr.PlayerCarLimted.GMCs.Value,
plr.PlayerCarLimted.ToytaSupra.Value,
}
local S, F = pcall(function()
PlayerData:SetAsync(plr.UserId, CarPlayer)
end)
if S then
print("Saved player data for " .. plr.Name)
else
warn("Error saving player data for " .. plr.Name .. ": " .. F)
end
end)
4 Likes
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.