Hey there! To keep it brief, I have this script where it supports a trail shop system. However, the script that I’m using to save two currencies isn’t working… Could anyone convert this into where it saves, and then tell me what I did wrong? I’d really appreciate it.
local StatsName = "Gold"
local StartingAmt = 1000
local DataStoreService = game:GetService("DataStoreService")
local RunService = game:GetService("RunService")
local PlayersService = game:GetService("Players")
local statsStore = DataStoreService:GetDataStore("-stats")
local StatsName1 = "Voids"
local StartingAmt = 0
local DataStoreService = game:GetService("DataStoreService")
local RunService = game:GetService("RunService")
local PlayersService = game:GetService("Players")
local statsStore = DataStoreService:GetDataStore("-stats")
---------------------
game.Players.PlayerAdded:Connect(function(Player)
local leaderFolder = Instance.new("Folder")
leaderFolder.Name = "leaderstats"
leaderFolder.Parent = Player
local statsValue = Instance.new("NumberValue")
statsValue.Value = StartingAmt
statsValue.Name = StatsName
statsValue.Parent = leaderFolder
local statsValue = Instance.new("NumberValue")
statsValue.Value = StartingAmt
statsValue.Name = StatsName1
statsValue.Parent = leaderFolder
local lastEquipped = Instance.new("StringValue")
lastEquipped.Value = "nil"
lastEquipped.Parent = Player
lastEquipped.Name = "equippedTrail"
local oldData
local foundData,newplr = pcall(function()
oldData = statsStore:GetAsync(Player.UserId)
end)
if foundData and oldData ~= nil then
statsValue.Value = oldData.Stat
lastEquipped.Value = oldData.equip
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
local succesSaved,ErrorSaved = pcall(function()
statsStore:SetAsync(Player.UserId,{
Stat = Player.leaderstats:FindFirstChild(StatsName).Value,
equip = Player.equippedTrail.Value,
})
end)
end)
game:BindToClose(function()
if RunService:IsStudio() then
wait(1)
else
for _, Player in pairs(PlayersService) do
local succesSaved,ErrorSaved = pcall(function()
statsStore:SetAsync(Player.UserId,{
Stat = Player.leaderstats:FindFirstChild(StatsName).Value,
equip = Player.equippedTrail.Value
})
end)
end
end
end)