Greetings,
Can someone please check why it doesn’t save the trails? Thanks!
local RS = game:GetService("ReplicatedStorage")
local DSS = game:GetService("DataStoreService")
local TrailTable = DSS:GetDataStore("TrailTable")
game.Players.PlayerAdded:Connect(function(player)
local trailfolder = Instance.new("Folder",player)
trailfolder.Name = "Trails"
local data = TrailTable:GetAsync(player.UserId.."-Trails")
if data then
for i, trail in pairs(data) do
local petFolder = Instance.new("Folder")
petFolder.Name = trail[1]
petFolder.Parent = player:WaitForChild("Trails")
local petName = Instance.new("StringValue")
petName.Name = "Name"
petName.Value = trail[1]
petName.Parent = petFolder
local petLevel = Instance.new("NumberValue")
petLevel.Name = "Level"
petLevel.Value = trail[2]
petLevel.Parent = petFolder
local petXP = Instance.new("NumberValue")
petXP.Name = "XP"
petXP.Value = trail[3]
petXP.Parent = petFolder
local petMultiplier = Instance.new("NumberValue")
petMultiplier.Name = "Multiplier"
petMultiplier.Value = trail[4]
petMultiplier.Parent = petFolder
end
else
print("No trails detected!")
end
end)
function saveTrails(player)
if player:FindFirstChild("Trails") then
local trailinventory = {}
for i, trail in pairs(player.Trails:GetChildren()) do
table.insert(trailinventory,{trail.Name.Value, trail.Level.Value, trail.XP.Value, trail.Multiplier.Value})
end
local succes,errorMessage = pcall(function()
TrailTable:SetAsync(player.UserId.."-Trails",trailinventory)
end)
if succes then
print("Trails saved!")
else
print("Error: "..errorMessage)
end
end
end
game.Players.PlayerRemoving:Connect(function(player)
saveTrails(player)
end)
game:BindToClose(function()
for i, player in pairs(game.Players:GetPlayers()) do
saveTrails(player)
end
end)
I made this script with a tutorial from AlvinBlox and a script from a different user.