if u dont understand heres what i mean, so when u get a new aura, a template ( textlabel ) clones and is placed in a frame for inventory, and uh i want it so whenever it clones it saves whenever player rejoins, i tried many things but it dont work heres my script ( some parts are not related )
local RarityModule = require(script.RarityModule)
local DataStoreService = game:GetService("DataStoreService")
local playerDataStore = DataStoreService:GetDataStore("PlayerData2")
local rarities = {
{name = "Common", chance = 50}, -- 1 in 2 white color
{name = "Uncommon", chance = 20}, -- 1 in 5 green color
{name = "Rare", chance = 15}, -- 1 in 6 blue color
{name = "Epic", chance = 10}, -- 1 in 10 purple color
{name = "Legendary", chance = 4}, -- 1 in 25 pink color
{name = "Mythic", chance = 0.9}, -- 1 in 111 red color
{name = "Godly", chance = 0.1} -- idk yellow color
}
local function savePlayerData(player)
local auraTemplates = {}
local playergui = player:WaitForChild("PlayerGui")
local inventory = playergui:WaitForChild("Inventory")
local auraFrame = inventory:WaitForChild("INV"):WaitForChild("Aura Frame")
for _, aura in ipairs(auraFrame:GetChildren()) do
if aura:IsA("TextLabel") and aura.Name:match("^Aura%d+$") then
table.insert(auraTemplates, aura.Text)
end
end
local success, errorMessage = pcall(function()
playerDataStore:SetAsync(player.UserId, {
MaxStorage = player.MaxStorage.Value,
Auras = #auraTemplates,
Templates = auraTemplates
})
end)
if not success then
warn("Failed to save data for player " .. player.Name .. ": " .. errorMessage)
end
end
local function loadPlayerData(player)
local success, data = pcall(function()
return playerDataStore:GetAsync(player.UserId)
end)
if success and data then
player.MaxStorage.Value = data.MaxStorage or 7
player.Auras.Value = data.Auras or 0
if data.Templates then
local playergui = player:WaitForChild("PlayerGui")
local inventory = playergui:WaitForChild("Inventory")
local auraFrame = inventory:WaitForChild("INV"):WaitForChild("Aura Frame")
for i, templateName in ipairs(data.Templates) do
local newtemplate = auraFrame:WaitForChild("AuraExample"):Clone()
newtemplate.Parent = auraFrame
newtemplate.Text = templateName
newtemplate.Name = "Aura" .. i
newtemplate.Visible = true
end
end
else
warn("Failed to load data for player " .. player.Name)
end
end
game.ReplicatedStorage:WaitForChild("Roll").OnServerEvent:Connect(function(player, whichroll)
RarityModule.setRarities(rarities, player)
local pickedRarity = RarityModule.pickRarity()
print("Picked Rarity: " .. pickedRarity.name)
game.ReplicatedStorage.Roll:FireClient(player, pickedRarity.name, 100 / pickedRarity.chance, whichroll)
end)
game.Players.PlayerAdded:Connect(function(player)
local canroll = Instance.new("BoolValue")
canroll.Parent = player
canroll.Value = true
canroll.Name = "CanRoll"
local latestroll = Instance.new("StringValue")
latestroll.Parent = player
latestroll.Value = "None"
latestroll.Name = "LatestRoll"
local latestroll2 = Instance.new("IntValue")
latestroll2.Parent = player
latestroll2.Value = 7
latestroll2.Name = "MaxStorage"
local latestroll23 = Instance.new("IntValue")
latestroll23.Parent = player
latestroll23.Value = 0
latestroll23.Name = "Auras"
loadPlayerData(player)
end)
game.Players.PlayerRemoving:Connect(function(player)
savePlayerData(player)
end)
game.ReplicatedStorage:WaitForChild("LatestRoll").OnServerEvent:Connect(function(player, name)
player:WaitForChild("LatestRoll").Value = name
local playergui = player:WaitForChild("PlayerGui")
local inventory = playergui:WaitForChild("Inventory")
local auraFrame = inventory:WaitForChild("INV"):WaitForChild("Aura Frame")
if #auraFrame:GetChildren() < player.MaxStorage.Value then
local newtemplate = auraFrame:WaitForChild("AuraExample"):Clone()
newtemplate.Parent = auraFrame
newtemplate.Text = name
player.Auras.Value += 1
newtemplate.Name = "Aura" .. player.Auras.Value
newtemplate.Visible = true
savePlayerData(player) -- Save data immediately after adding a new template
end
end)