1012714707-MaxHealth is not a valid member of GlobalDataStore
why this error when i try to save game?

local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")


game.Players.PlayerAdded:Connect(function(player)
	local data
	local success, errormessage = pcall(function()
		data = myDataStore:GetAsync(player.UserId.."-MaxHealth")
	end)
	if success then
		print("Successfully loaded your data!")
	    else
		print("Your Data failed to load!")
		warn(errormessage)
	end
end)

game.Players.PlayerRemoving:Connect(function(player)

   local success, errormessage = pcall(function()
	myDataStore(player.UserId.."-MaxHealth",player.MaxHealth.Value)
  end)
  if success then 
	print("Your Data Successfully Saved!")
  else
	print("Your Data Has Ben Corrupted and failed to save!")
	print(errormessage)
end
end)

2 comments

0

Is MaxHealth directly under player or is it in a folder?

0

ZSQD_royalzombie222 is game.Players.LocalPlayer.MaxHealth.Value