So I was making a script that creates a Table value with the players data in it (Such as: Unlocked Levels, Skins)

And I have this Level Selector GUI, each level is an obby and you have the ability to teleport between levels you have already been inside

You know how the GUI always resets whenever the character spawns. Well I tried to make a script to counter that

here it is

	-- Save and load player data when dying
	local LatestSaveBeforeDeath

	Player.CharacterAdded:Connect(function(Character)

		local Humanoid = Character:WaitForChild("Humanoid")
		wait()
		print("Humanoid FOUND!")

		Humanoid.Died:Connect(function()
			LatestSaveBeforeDeath = EncodeSave()
			print("Encoded save before respawning")
		end)
		
		if LatestSaveBeforeDeath ~= nil then
			print("Retreiving Data from previous death")
			LoadSave(LatestSaveBeforeDeath)
			print("Loaded save from earlier death")
		else	
			print("Waiting for player to die to get the save")
		end
	end)

the functions, EncodeSave() and LoadSave() works fine however in line 12 the "print" doesn't work and the LatestSaveBeforeDeath is nil so it doesn't work

Am I doing something wrong? And if you need more information you can ask me!

1 comment

0

You just need to add a repeat loop for the player's character to completely load up and it will work perfectly fine! Also, add it before your Humanoid variable.