it’s a bit long
but sure!
it’s not the entire script,
it’s just the function that initializes player data, as the name suggests
function InitializePlayerData(plr: Player)
local totalKills = GetOrCreateAttribute(plr, "TotalKills", 0)
local totalDeaths = GetOrCreateAttribute(plr, "TotalDeaths", 0)
local totalCurrencyEarned = GetOrCreateAttribute(plr, "TotalCurrencyEarned", 0)
local totalVoidstonesEarned = GetOrCreateAttribute(plr, "TotalVoidstonesEarned", 0)
local totalXpEarned = GetOrCreateAttribute(plr, "TotalXpEarned", 0)
local currentLevel = GetOrCreateAttribute(plr, "CurrentLevel", 1)
local currentCurrency = GetOrCreateAttribute(plr, "Zetabonds", 0)
local currentVoidstones = GetOrCreateAttribute(plr, "Voidstones", 0)
local currentXp = GetOrCreateAttribute(plr, "CurrentXp", 0)
local currentClass = GetOrCreateAttribute(plr, "CurrentClass", "Survivor")
local currentWhisper = GetOrCreateAttribute(plr, "CurrentWhisper", 0)
-- 'Whisper' is basically a rebirth, but with an edgy name
-- so think of 'Whisper' as 'Rebirth' if you find it easier
local success, result = pcall(function()
return playerDataStorage:GetAsync(plr.UserId)
end)
-- some player variables;
local char = plr.Character
local characterClothesFolder: Folder = char:FindFirstChild("Clothes")
if not success then
warn("Failed to fetch " .. plr.UserId .. "'s data!")
warn("Error log: " .. result)
result = nil
end
if not playerDataTable[plr.UserId] then
-- Set data;
playerDataTable[plr.UserId] = {
TotalKills = totalKills,
TotalDeaths = totalDeaths,
TotalCurrencyEarned = totalCurrencyEarned,
TotalVoidstonesEarned = totalVoidstonesEarned,
TotalXpEarned = totalXpEarned,
CurrentLevel = currentLevel,
CurrentCurrency = currentCurrency,
CurrentVoidstones = currentVoidstones,
CurrentXp = currentXp,
CurrentClass = currentClass,
CurrentWhisper = currentWhisper,
Settings = {
-- Default values
["Field of View"] = 90,
["Classic Aim Down Sights"] = false,
["Vitals GUI Color"] = Color3.fromRGB(255,255,255),
["Weapon GUI Color"] = Color3.fromRGB(255,255,255),
["Visible Viewmodel"] = true,
["Show Crosshair"] = true,
["First Person Tracers"] = true,
["Show Blood"] = true,
["Show Rewards"] = true
},
Clothing = {
-- Default values
["tops"] = "StarterTop_Shirt",
--["bottoms"] = "StarterBottom_Pants"
}
}
end
if result then
playerDataTable[plr.UserId].TotalKills = result.TotalKills or totalKills
playerDataTable[plr.UserId].TotalDeaths = result.TotalDeaths or totalDeaths
playerDataTable[plr.UserId].TotalCurrencyEarned = result.TotalCurrencyEarned or totalCurrencyEarned
playerDataTable[plr.UserId].TotalXpEarned = result.TotalXpEarned or totalXpEarned
playerDataTable[plr.UserId].CurrentLevel = result.CurrentLevel or currentLevel
playerDataTable[plr.UserId].CurrentWhisper = result.CurrentWhisper or currentWhisper
playerDataTable[plr.UserId].CurrentCurrency = result.CurrentCurrency or currentCurrency
playerDataTable[plr.UserId].CurrentVoidstones = result.CurrentVoidstones or currentVoidstones
playerDataTable[plr.UserId].CurrentXp = result.CurrentXp or currentXp
playerDataTable[plr.UserId].CurrentClass = result.CurrentClass or currentClass
local vitalsGuiColorDeserialized = Deserialize(result.Settings["Vitals GUI Color"])
local weaponGuiColorDeserialized = Deserialize(result.Settings["Weapon GUI Color"])
-- change the settings blah blah
for setting, value in pairs(result.Settings) do
playerDataTable[plr.UserId].Settings[setting] = value
end
-- then we change the clothing
for clothingType, clothingName in pairs(result.Clothing) do
playerDataTable[plr.UserId].Clothing[clothingType] = clothingName
-- and also apply it to the player's character
-- but first we need to destroy it
local clothingToClone = GetClothingFromName(clothingName)
local clothing = clothingToClone:Clone()
RemovePreviousClothingWithSameType(characterClothesFolder, clothingType)
clothing.Parent = characterClothesFolder
print(clothing.Parent)
print(clothing)
print(characterClothesFolder.Parent)
print(characterClothesFolder.Parent.Parent)
end
playerDataTable[plr.UserId].Settings["Vitals GUI Color"] = vitalsGuiColorDeserialized
playerDataTable[plr.UserId].Settings["Weapon GUI Color"] = weaponGuiColorDeserialized
plr:SetAttribute("TotalKills", playerDataTable[plr.UserId].TotalKills)
plr:SetAttribute("TotalDeaths", playerDataTable[plr.UserId].TotalDeaths)
plr:SetAttribute("TotalCurrencyEarned", playerDataTable[plr.UserId].TotalCurrencyEarned)
plr:SetAttribute("TotalVoidstonesEarned", playerDataTable[plr.UserId].TotalVoidstonesEarned)
plr:SetAttribute("TotalXpEarned", playerDataTable[plr.UserId].TotalXpEarned)
plr:SetAttribute("CurrentLevel", playerDataTable[plr.UserId].CurrentLevel)
plr:SetAttribute("CurrentWhisper", playerDataTable[plr.UserId].CurrentWhisper)
plr:SetAttribute("Zetabonds", playerDataTable[plr.UserId].CurrentCurrency)
plr:SetAttribute("Voidstones", playerDataTable[plr.UserId].CurrentVoidstones)
plr:SetAttribute("CurrentXp", playerDataTable[plr.UserId].CurrentXp)
plr:SetAttribute("CurrentClass", playerDataTable[plr.UserId].CurrentClass)
end
returnPlayerSettings:FireClient(plr, playerDataTable[plr.UserId].Settings)
end