Here’s a section of my script, please don’t stop reading because of the first script’s length, it’s just there for context of what i’m doing. I’m creating a Folder inside the Player with Values representing the player’s data, and when a value changes, i want to update the data. Everything works, except for the updating the data part
local PlayerAdded = function(Player)
-- Get's player's profile.Data
local PlayerData = (DataManager.GetData(Player)).Data
-- Create folder that represent's PlayerData.Data
local DataFolder = Instance.new("Folder")
DataFolder.Name = "DataFolder"
DataFolder.Parent = Player
-- no need to read this except for the last function, it works as intended
for Name, BigBoy in pairs(PlayerData) do
local NewValue, ParentFolder
-- If Player.Data has a table inside it, creates another SubFolder representing it
if typeof(BigBoy) == "table" then
local NewFolder = Instance.new("Folder")
NewFolder.Name = Name
NewFolder.Parent = DataFolder
-- Creates Value instance inside SubFolder
for Key, Value in pairs(BigBoy) do
NewValue = CreateNewValueInstance(NewFolder, Key, Value)
ParentFolder = NewFolder.Name
end
end
NewValue.Changed:Connect(function()
-- This is the part that doesn't work
PlayerStatChange(NewValue, PlayerData, ParentFolder)
end)
end
end
Result:
This is all that i have put into the player Data so far, so it’s working perfectly
Now for the .Changed event
-- Let's say i change the "Strength" value from 1 to 2, this script would run
local PlayerStatChange = function(NewValue, PlayerData, ParentFolder)
-- The variables would have the following values:
-- Strength(Instance), My Profile.Data, "Statistics"
local ChangedData = PlayerData[ParentFolder][NewValue.Name] -- This is the same as = Profile.Data.Statistics.Strength
-- This print's out the Players Strength as it should
print(ChangedData) -- 1
-- Now this line should change it to 2 (i think), but it doesn't
ChangedData = NewValue.Value
end
Tf do i do?