i need to save the value of a stringvalue if that makes sense. right now im saving values inside of a table and then making new stringvalues when the player joins and add them into a folder but the values will be blank how do i save the value and then load it into the string value? with Datastore2 btw
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DataStore2 = require(ReplicatedStorage:WaitForChild("DataStore2"))
DataStore2.Combine("MasterKey","PlayerDatastore")
local DefaultData = {
Coins = 0,
Exp = 0,
Level = 1,
SkillPoints = 0,
Health = 100,
Physical = 0,
Spell = 0,
EquippedWeapon = "None",
EquippedArmor = "None",
EquippedHelmet = "None",
EquippedSpell1 = "None",
EquippedSpell2 = "None",
OwnedItems = {},
}
game.Players.PlayerAdded:Connect(function(player)
--local character = player.Character or player.CharacterAdded:Wait()
local PlayerDatastore = DataStore2("PlayerDatastore", player)
local Data = PlayerDatastore:Get(DefaultData)
local DataFolder = script.DataFolder:Clone()
DataFolder.Parent = player
DataFolder.Coins.Value = Data.Coins
DataFolder.Exp.Value = Data.Exp
DataFolder.Level.Value = Data.Level
DataFolder.SkillPoints.Value = Data.SkillPoints
DataFolder.Health.Value = Data.Health
DataFolder.Physical.Value = Data.Physical
DataFolder.Spell.Value = Data.Spell
DataFolder.EquippedArmor.Value = Data.EquippedArmor
DataFolder.EquippedHelmet.Value = Data.EquippedHelmet
DataFolder.EquippedSpell1.Value = Data.EquippedSpell1
DataFolder.EquippedSpell2.Value = Data.EquippedSpell2
DataFolder.EquippedWeapon.Value = Data.EquippedWeapon
for i, item in pairs(Data.OwnedItems) do
local ItemV = Instance.new("StringValue")
ItemV.Name = item
ItemV.Value = "Legendary" --need this value to save and load whatever it is (common, legendary, rare etc..)
ItemV.Parent = player.DataFolder.OwnedItems
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local Data = {}
local OwnedItems = {}
local PlayerDatastore = DataStore2("PlayerDatastore", player)
for i,v in pairs(player.DataFolder:GetChildren()) do
if v.ClassName ~= "Folder" then
Data[v.Name] = v.Value
elseif v.ClassName == "Folder" and v.Name == "OwnedItems" then
for i, item in pairs(v:GetChildren()) do
table.insert(OwnedItems, item.Name)
end
end
end
Data["OwnedItems"] = OwnedItems
PlayerDatastore:Set(Data)
PlayerDatastore:Save()
end)