I’m trying to save leaderstats and other valeus in one script with the other values in a table so its easy, but its not working does anyone know why?
heres the script:
local DataStoreService = game:GetService("DataStoreService")
local playerData = DataStoreService:GetDataStore("PlayerData")
local playerValuesTable = {"Multiplier"}
local function onPlayerJoin(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local number = Instance.new("IntValue")
number.Name = "Number"
number.Parent = leaderstats
local playerValues = Instance.new("Folder")
playerValues.Name = "PlayerValues"
playerValues.Parent = player
local playerUserId = "Player_" .. player.UserId
local data = playerData:GetAsync(playerUserId)
for index, value in pairs(playerValuesTable) do
local newValue = Instance.new("IntValue")
newValue.Name = value
newValue.Parent = playerValues
if data then
newValue.Value = data
number.Value = data
else
number.Value = 0
newValue.Value = 0
end
end
end
local function onPlayerExit(player)
local success, err = pcall(function()
local playerUserId = "Player_" .. player.UserId
playerData:SetAsync(playerUserId, player.leaderstats.Number.Value)
for i, v in pairs(player.PLayerValues:GetChildren()) do
playerData:SetAsync(playerUserId, v.Value)
end
end)
if not success then
warn('Could not save data!')
end
end
game.Players.PlayerAdded:Connect(onPlayerJoin)
game.Players.PlayerRemoving:Connect(onPlayerExit)