First, the code:
local lib = assert(LoadLibrary("RbxUtility"))
game.Players.PlayerAdded:connect(function(p)
p.Character.Humanoid.Died:connect(function()
local credittab = lib.DecodeJSON(p.PlayerGui.Creds.Value)
p.CharacterAdded:connect(function(char)
p.PlayerGui.Creds.Value = lib.EncodeJSON(credittab)
end)
end)
end)
Now let me explain what I am trying to do:
There is a value in PlayerGui called "Creds" which holds a JSON string indicating how many Credits a player has. However, whenever the player resets, this value is reset. I am trying to prevent that from happening.
I have previously (before the above version of the script) attempted this:
local lib = assert(LoadLibrary("RbxUtility"))
game.Players.PlayerAdded:connect(function(p)
p.Character.Humanoid.Died:connect(function()
local credittab = lib.DecodeJSON(p.PlayerGui.Creds.Value)
repeat wait() until p.Character
wait(1)
p.PlayerGui.Creds.Value = lib.EncodeJSON(credittab)
end)
end)
As well as this:
local lib = assert(LoadLibrary("RbxUtility"))
game.Players.PlayerAdded:connect(function(p)
p.Character.Humanoid.Died:connect(function()
local credittab = lib.DecodeJSON(p.PlayerGui.Creds.Value)
repeat wait() until p.CharacterAdded
wait(1)
p.PlayerGui.Creds.Value = lib.EncodeJSON(credittab)
end)
end)
I believe the problem may lie with my lack of understanding of .Died.
If you require any extra information to fully understand my question, please ask.
